Input in Java
Input in Java
Java Scanner class allows the user to take input from the console. It belongs
to java.util package. It is used to read the input of primitive types like int, double, long,
short, float, and byte. It is the easiest way to read input in Java program.
Scanner sc=new Scanner(System.in);
int nextInt() It is used to scan the next token of the input as an
integer.
float nextFloat() It is used to scan the next token of the input as a float.
byte nextByte() It is used to scan the next token of the input as a byte.
boolean nextBoolean() It is used to scan the next token of the input into a
boolean value.
long nextLong() It is used to scan the next token of the input as a long.
short nextShort() It is used to scan the next token of the input as a Short.