Type ( four types and eight types ) + basic usage of Scanner
import java.util.Scanner;
/*java data type
Numerical
Integer: byte : ( 1 byte) -128~127
short : ( 2 bytes) -32768~32767
int : ( 4 bytes) -2^31~2^31-1
long : ( 8 bytes) -2^63~2^63-1
Float: float default 0.0F
double default value 0.0
non-numeric
Character type: char
boolean: boolen : true/false default value false
The above 8 are the basic data types of Java
String type: String
Other Java types
custom type */
(This picture comes from the Internet)
public class BK{
// After entering main , alt+/ can pop up the Enter operation, and press Enter to quickly generate
public static void main(String[] args) {
// Use a variable to display the change of the deposit
double money=1000;
// The shortcut is sysout.+a;t/
System.out.println("The original amount is: "+money );
money=money*0.05+money;
// String concatenation, join the string and the variable with the plus sign to form a new character
System.out.println("The current amount is: "+money);
/* The output name is; Xiao Ming
age is 25
Participated in 5 projects
The preferred language is Java
hobby for basketball
*/
String name="小明";
System.out.println("This classmate's name is: "+name);
int age=25;
System.out.println("The age of this classmate is: "+age);
char ite='5';
System.out.println("The number of projects this student participated in: "+ite);
String sky="Java";
System.out.println("The language this classmate is good at is: "+sky+'class');
String hobby="basketball";
System.out.println("This classmate's hobby is: "+hobby);
/*scanner usage
The first step: import the sacnner class import Java.until.*; ( written in the beginning of the public class)
Step 2: Create Scanner object Sacnner input=new Scanner ( system.in);// Construct Scanner class object sc to receive the information input from the console
The third step: print out the prompt symbol System.out.println ( " prompt text);
Step 4: Get the data entered by the keyboard int now=input.nextlnt();
Step 5: Print the output value: System.out.println(" The value of the print output is : ");
/* Enter name: Wang Liu
Input ID : 123*/
Scanner sc=new Scanner(System.in); // Construct the object sc of the Scanner class to receive the information input from the console
System.out.println("Please enter your name:");
String name1=sc.next();//Receive the string on the keyboard
System.out.println("Please enter your ID:");
int ID=sc.nextInt();
System.out.println("Your name is: "+name1);
System.out.println("Your ID is: "+ID);
}
}