import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
int number = 0;
int keyValue = System.in.read();
keyValue = keyValue - 48;
number = number * 10 + keyValue;
System.out.println(number);
while(true) {
keyValue = System.in.read();
keyValue = keyValue - 48;
number = number * 10 + keyValue;
System.out.println(number);
if(keyValue == 120) {
number = number - 120;
System.out.println(number);
break;
}
}
}
}
I want to get integer value from the keyboard. subtracting 48 is gonna make ASCII Code to be a value that I entered on a keyboard.
I don't only want to do this in first digit, but make a integer whatever I enter on a keyboard, using while loop and if condition.
What do you think is the problem? please help me.
'0'is clearer, and equivalent.System.inbuffers input.System.in.read()won't return anything until it is flushed, e.g. by pressing enter or closing the stream.