Reputation: 21
I got error from my code,
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.print("a = ");
int a=in.read();
System.out.print("b = ");
int b=in.read();
System.out.print(" = "+a);
System.out.print("b = "+b);
i try to input 1, and i dont understand why the result like this?
a = 1
b = = 49b = 13
Where is the second input going?
Upvotes: 1
Views: 40
Reputation: 18968
You can try something like this:
a = in.readLine();
System.out.print("b = ");
String b=in.readLine();
int aInt = Integer.valueOf(a);
int bInt = Integer.valueOf(a);
System.out.print("a = "+aInt);
System.out.print("b = "+bInt);
read()
reads character by character, so newline will be counted as new character. To read more about it you can read here.
Upvotes: 2