Skip to content

Reading a number

Read · 1 of 4

Scanner reads input

Add import java.util.*; at the very top, then make a Scanner once: Scanner in = new Scanner(System.in);.

in.nextInt() reads the next whole number, in.nextLong() a big one, in.nextDouble() a decimal and in.next() the next word.

On DSA sites, the input is already written in a file and fed to your program, so your program shouldn't print questions like "Enter a number".