Java Fundamentals (Chapter two)
One, variable
1. A variable is an identifying symbol in memory that is used to store the data
2. Variable naming rules
L must start with a letter, underscore _, dollar sign $
l variables, which can include numbers
L variable, cannot appear special symbol, space
L keywords in Java (red font), cannot do variable name
3. Variable naming, followed by camel nomenclature (variables are made up of more than 1 words, the first letter of the 1th Word is lowercase, and the first letter of the following word is capitalized)
Second, the data type
A) number ( int(integer), double-precision floating-point double (decimal))
b) Character type (char), storing a single character
c) string character (string), storing multiple characters
Iii. How to declare variables and assign values to variables (Assignment operator =)
Method 1: Declare first, then assign value
Syntax: data type variable name; ( int i ;)
Variable name = value; ( i=0; )
Method 2: Assign a value directly when declaring a variable
Syntax: data type variable name = value; ( int i=0 ;)
Remember: Variables are declared first, then assigned, and then used
Iv. input data from the keyboard
Step 1: In the first line of the current code file, import the package
Import java. util.*; or Import java. util. Scanner;
Step 2: Write the statement (write only once)
Scanner input=new Scanner (system.in);
Step 3: Define the variables and save the data entered by the keyboard
Data type variable name =input.next data type ();
┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉
Arithmetic operators
+,-,*(multiplication sign),/(division sign, pick-up),%(take remainder, modulo)
Special operators: ++ ( gaga ) , -- ( minus )
int a = 1;
a+=10; equivalent to a=a+10;
a-=5; equivalent to a=a-5;
int a = 1;
Scene 1:system.out.print (a++);//Output 1
int a = 1;
Scene 2:system.out.print (++a);//Output 2
Relational operators
Greater than:> less than:< greater than or equal to:>= less than equals:<= equals sign:= = Not equal to: /c6>!=
┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉
Five, Boolean data types
Boolean: A value of TRUE or False
Assignment: The boolean variable name =true or false or an expression;
Data type Conversions ( for numeric types )
1, divided into 2 major categories:
numeric type (int, double),
Non-numeric type (character ', String ', Boolean type bool)
2. Data type Conversion classification
A) automatic type conversion--"P41 page"
I. Rule 1: If one operand is of type double, the entire expression can be promoted to a double type
Ii. Rule 2: Conditions for automatic type conversions are met.
Two types are compatible: numeric types (int and floating-point double)
Destination type is greater than Source type: Double type can hold int type,(int-->double"enlarge transform")
b) Coercion type conversion: Target type variable name = (target type) variable or expression;
"A value of type double, saved to the INT type variable"
int variable name =(int)a value or variable of type double;
Java Fundamentals (Chapter two)