Hi there,

I'm working on a simple java program that allows a user to input numbers via console, throws an exception when a string is entered, and tallys up and prints the integers when the user simply hits enter with no input.
i.e.
Please enter a value: 5
Please enter a value: five
Error: Please enter a value.
Please enter a value: 4
Please enter a value:
9

My question is what does Scanner read or categorize as "Enter", I want to try an if (in.next().equals or == \n or something), but I don't know if thats what I need to do, or if there is a Scanner method I am not seeing/understanding that returns a boolean for it.

Nevermind, I didn't realize it was as easy as something like
String input;
input = in.nextLine();
if (input.equals("") {
done = true;
}

hi! not speak English very well, but let me attempt a task in JCreator and the program has to read the key pressures, I'm doing it like this:

import java.util.Scanner;

public class leerTeclado {
public static void main(String[] args) {

Scanner lectura = new Scanner (System.in);
Scanner leeCadena = new Scanner (System.in);


System.out.println(


How do I read "Enter"? Also Ctrl and Alt .. Or can not?

my email is yujagli_AM@hotmail.com

hi! not speak English very well, but let me attempt a task in JCreator and the program has to read the key pressures, I'm doing it like this:


import java.util.Scanner;

public class leerTeclado {
public static void main(String[] args) {

Scanner lectura = new Scanner (System.in);
Scanner leeCadena = new Scanner (System.in);


System.out.println("Oprima una Tecla");
String tecla = leeCadena.nextLine();
System.out.println ("La tecla es : " + tecla);

}
}


How do I read "Enter"? Also Ctrl and Alt .. Or can not?

my email is yujagli_AM@hotmail.com

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.