Alex Rivera | Logout

How can I read input from the console using the Scanner class in Java?

Asked 2012-08-08T19:13:07.250
251

How could I read input from the console using the Scanner class? Something like this:

System.out.println("Enter your username: ");
Scanner = input(); // Or something like this, I don't know the code

Basically, all I want is have the scanner read an input for the username, and assign the input to a String variable.

Edit
Report

1 Answer

35
Scanner scan = new Scanner(System.in);
String myLine = scan.nextLine();
answered 2012-08-08T19:15:37.593

Your Answer