I used the following code segment to get 10 inputs from console in java and tried to print them for example in *******12
format. In run-time, I entered 12,13,14,15 as inputs and then the program terminated. Now there are 3 questions:
- Why this code gets only 5 inputs instead 10?
- Why this code prints for example 49,52,10 for input 14?
- What's the solution?
Code:
public static void main(String[] args) {
for (int i = 0 ; i <10 ;i++){
try {
int j= System.in.read();
System.out.println("**********"+j);
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
and the output was:
12
**********49
**********50
**********10 13
**********49
**********51
**********10 14
**********49
**********52
**********10 15
**********49
BUILD SUCCESSFUL (total time: 14 seconds)