Skip to content

Whole lines

Watch it run · 1 of 2

A number, then a line

1import java.util.*;
2
3public class Main {
4 public static void main(String[] args) {
5 Scanner in = new Scanner(System.in);
6 int n = in.nextInt();
7 in.nextLine();
8 String title = in.nextLine();
9 System.out.println(n + " x " + title);
10 }
11}

Memory

int n

3

Typed input

3
Data Structures

Output

(nothing yet)

line 6nextInt reads 3, but stops right before the end of that line.

step 1 of 4