i have to read from the following format.
1
12
23
34
So, All inputs are separated by a line.
I have tried the following
br = new Scanner(System.in);
num = Integer.parseInt(br.next());
while(br.hasNextInt()) {
num = br.nextInt() ;
System.out.println(num);
}
But it is not working as i expected. If i enter first input, it started processing it and prints. it is not waiting for me to enter next line. In C, i can make use of sscanf. but in java i have no idea how to allow user to enter multiline input? plese suggest some ideas
Try
br = new Scanner(System.in);
while (true) {
int num = Integer.parseInt(br.nextLine());
System.out.println(num);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With