CJCoding With Joseph
15per day
← Back to Question List
Java Code Walkthrough #31

nextLine After nextInt

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