Java read system input in while loop -
Here's a very simple code, in which I want input from the keyboard in a loop. For every input, the loop is automatically running two extra time and takes the values of 13 and 10, whatever I have given in the form of input. Can you please tell me what I am doing wrong?
CODE:
Public static zero main (string agr []) {BufferedReader br = new BufferedReader (New InputStreamReader System.in)); Boolean loop_cond = true; Int n = 1; While (loop_cond == true) {try {System.out.print ("Input:"); N = br.read (); } Hold (IOException e) {e.printStackTrace (); } System.out.print (n + "\ n"); Input: 6 54 Input: 13 Input: 10 Input: 9 57 Input: 13 Input: 10 Input: : 1 49 Input: 13 Input: 10 Input:
This probably \ r \ N Try the scanner to take the value values.
scanner input = new scanner (System.in); Int i = input.nextInt ();
Comments
Post a Comment