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.
- Integer data using: Cc.nestint () to receive
- Double precision Use: cc.nextdouble () to receive
- 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