I genius the official free tutorial 22: Java Common class receive console input scanner class

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.