Java Data entry

Source: Internet
Author: User

The following is an example of a data entry:

The following is a data entry instance
import Java.util.Scanner; //import Java.util.scanner,scanner first letter capitalization
 Public class test2{
 Public Static void Main (String[]args) {
Scanner cc =new Scanner (system.in); //Declare a new scanner cc, and assign a value
System.out.print (" Please enter your name:");
String Name=cc.next (); //Use name to access user input data, the following age and JG are the same
System.out.print (" Please enter your age:");
int age = Cc.nextint ();
System.out.print (" Please enter your hometown:");
String JG =cc.next ();
System.out.println ("-----------------\ n Name:" +name+ "\ n Age:" +age+ "\ n Native:+JG);
}
}

Note: The type of data received will be wrong.

    1. Integer data using: Cc.nestint () to receive
    2. Double precision Use: cc.nextdouble () to receive
    3. String using: Cc.next () to receive, no Cc.nextchar () This method to receive the input of a single note

The above CC is a self-declared scanner, of course you can also use other characters

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.