CJCoding With Joseph
15free / daySign inCreate account
Back to Code Walkthrough

nextLine After nextInt

Java code walkthrough · Question 31
mediumStrings
User input (stdin)
21\nJoseph\n
This is the input fed to the program

Code

Read carefully. What does this print?
1import java.util.Scanner;
2 
3public class Main {
4 public static void main(String[] args) {
5 Scanner input = new Scanner(System.in);
6 
7 int age = input.nextInt();
8 String name = input.nextLine();
9 String city = input.nextLine();
10 
11 System.out.println("age=" + age);
12 System.out.println("name=" + name);
13 System.out.println("city=" + city);
14 }
15}

Your answer