0
Why we can't give input to string variable just after giving input to numerical variable like int in java using Scanner?
2 Answers
+ 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
+ 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