Posts Tagged user input

Using Scanner class to get input from user in java

java.util.Scanner class provides a way to get input from user:

Scanner scanner = new Scanner(;

If input is String:

String string= scanner.nextLine();//to read input as a whole line


String string=; // to read single word

To read integers:

int i= scanner.nextInt();

Here is an article helpful on Scanner.


Leave a comment