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(System.in);

If input is String:

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

or

String string= scanner.next(); // to read single word

To read integers:

int i= scanner.nextInt();

Here is an article helpful on Scanner.

,

Leave a comment