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

前端 未结 15 1937
我寻月下人不归
我寻月下人不归 2020-11-21 06:19

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

System.out.println(\"Enter your username: \");
Scanner = i         


        
15条回答
  •  迷失自我
    2020-11-21 06:43

    You can use the Scanner class in Java

    Scanner scan = new Scanner(System.in);
    String s = scan.nextLine();
    System.out.println("String: " + s);
    

提交回复
热议问题