0

Why we can't give input to string variable just after giving input to numerical variable like int in java using Scanner?

5th Aug 2019, 7:10 PM
Subroto Kumar
Subroto Kumar - avatar
2 Antworten
+ 3
Scanner sc = new Scanner(System.in); int val = sc.nextInt(); sc.nextLine(); // this one will consume new line after int from previous line String s = sc.nextLine(); // your another input
5th Aug 2019, 8:21 PM
Michal
Michal - avatar
+ 2
using .next() will allow you to enter your ints and and strings in the same line in the input box: Scanner scan = new Scanner(System.in); int age = scan.nextInt(); String name = scan.next(); input box: 23 Jake
5th Aug 2019, 10:47 PM
Jake
Jake - avatar