java how to read in userinput

Solutions on MaxInterview for java how to read in userinput by the best coders in the world

showing results for - "java how to read in userinput"
Mira
11 May 2019
1import java.util.Scanner;  // Import the Scanner class
2
3class Main {
4  public static void main(String[] args) {
5    Scanner myObj = new Scanner(System.in);  // Create a Scanner object
6    System.out.println("Enter username");
7
8    String userName = myObj.nextLine();  // Read user input
9    System.out.println("Username is: " + userName);  // Output user input
10  }
11}
12