Why Number lower than 9
is printed twice in my console, in the bellow code example?
public static void main(String[] args) throws java.io.IOException {
System.out.println("Input from keyboard should be '49'");
char e;
for (int a = 0; ; a++) {
e = (char) System.in.read();
if (e == 49)
break;
else
System.out.println("Use number lower than 9");
}
}
And here is the output when you type anything except of number 1:
run:
Input from keyboard should be '49'
2
Number lower than 9
Number lower than 9
Edit
Basicly, I am trying to get an input from console and store it inside char e
. What I'm getting after I type 1
is value 49
. That's why I used in code above e == 49
. I dont know how to retrieve just character 1
. Next thing is that i used an infinite loop to force the input to ask for specific character until its the correct one.