Scanner Class (Learn about it)
Using the scanner class to receive input from the keyboard
1. Syntax for creating Scanner objects: Scanner scan = new Scanner (system.in);
2. Use scanner object to receive keyboard input: Scan.next ();//wait and receive keyboard input
instance:package common_class;import java.util.scanner;/** * Demo Scanner class * Impersonate a user login * @author Genius Federation - Yukun */public class scannerdemo { Public static void main (String[] args) {//Create scanner Object scanner scan = New scanner (system.in);//Prompt for user name System.out.println ("Enter user name:");//Receive user input string string username = scan.next ()///Prompt for password System.out.println ("Please enter password:");//Receive the user input string String password = scan.next ( ;// output the value entered by the user System.out.println ("The user name you entered is:" + username); SYSTEM.OUT.PRINTLN ("The password you entered is:" + password);// if the username and password are entered by admin, the output login succeeds if (Username.equals ( "Admin") && password.equals ("admin")) {system.out.println ("Login Successful");}  ELSE {SYSTEM.OUT.PRINTLN ("Login Failed");} System.out.println ("Please enter Age:");// receive the user input integer int age = scan.nextint (); System.out.println ("The Age you entered is:" + age);}}
This article from the "Genius Union Education Official Blog" blog, reproduced please contact the author!
I genius the official free tutorial 22: Java Common class receive console input scanner class