Common commands:
"F:" enters the specified drive letter
"CD path": Enter under the specified path
Javac compiling
Java execution
Identifier:
Data type: base data type, reference data type
Today's content:
Constant: 13
Variables: A piece of content can change memory, store data
Variable Name: identifier
Variable value: In-memory data
Variables want to be used, then must be declared after the assignment
Declared format: data type variable name;
Format of assignment: variable name = variable value;
Data type (declaration) Variable name = variable value (assigned value);
Example: int num = 12;
Format: Data type variable name [= value];
What is the difference between a character and a string?
Character: single quote with only one character inside
String: Double quotes, inside can have more than one character
BYTE range: 128 to 127
Java's integer type defaults to int, and decimal data defaults to double type.
Format: Data type variable name [= value]
Data type:
1. Basic data type: Data type is basic type
2. Reference data type variable: Data type is reference type
Scope points:
1. Local variables: Variables defined in the method block (variables declared in the method code block), scoped to the method's interior
2. Global variables: Defined inside the class, outside of the method, acting on the entire class
Operators in Java:
1. Arithmetic operators + 、—、 *,%, + + 、--
Example: int b= + + (++i);//No, error. equivalent to int b= + + (i=1); it's not legal.
int c*=i++;//is wrong,
int c=2;c*=i++; or c*=++i; it's all right. c*=++ (i++); or c*=--(++i); it's all wrong.
int i=1;
int b=++ (++i);//No, wrong
int c*=i++;//is wrong,
2. Assignment Operator: Primary assignment
=, + =,-=,/=,%=
3, relational operators >, <, >=, <=, = =,! =, the result is a Boolean type.
4, logical operators: Mainly used in Boolean type, the result is a Boolean type
! (non):!true==false
^ (XOR): True^false==true,true^true==false
& (with): And true is true at the same time
&& (short circuit and): True at the same time
| (or): or, as long as one is true, the result is true
|| (Short circuit or): or, as long as one is true, the result is true
What is the difference between short circuit and and?
With (&): The right expression is verified regardless of whether the left is false
Short circuit and (&&): As long as the left to false, then the right side will not be verified
or (|) : Verifies the right expression regardless of whether the left is true
Short Circuit or (| |): As long as the left is true, then the right side is not verified
8, int a = 5;
int b = 4;
Boolean B9 = (a++) > (--b) & (--a)% (b++) ==1 & (a--) < (b--);
System.out.println (b9+ "\ t" +a + "\ T" +b);//
5>3&5%3==1&5<4
True&false&false=false
a=4,b=3;
A = 5;
b = 4;
Boolean B10 = (a++) > (--b) && (--a)% (b++) ==1 && (a--) < (b--);
System.out.println (b10+ "\ t" +a + "\ T" +b);
true&&false&& (a--) < (b--) =false
A=5,b=4
9, a = 6;
b = 9;
Boolean B11 = (a--)/(b++) <2 | (--a) * (--b)!=4 | (a++)% (b--) ==2;
System.out.println (b11+ "\ t" +a + "\ T" +b);//
6/9<2|4*9!=4|4%9==2
True
A=5,b=8
A = 6;
b = 9;
Boolean b12 = (a--)/(b++) <2 | | (--a) * (--b)!=4 | | (a++)% (b--) ==2;
System.out.println (b12+ "\ t" +a + "\ T" +b);
True
a=5,10
5, bitwise operators: Each binary number is manipulated
Bit: is a binary number: 0 or 1
Bytes: b consisting of 8-bit binary
~ (bitwise reverse): Take the opposite
^ (bitwise XOR): Same as 0, different 1
| (bitwise OR): Same as, 1 different
& (Bitwise AND): Same with, XOR 0
Conversions between binary and decimal:
Conversion between binary and decimal?
Decimal----> Binary: In addition to 2 of the remainder, as far as possible
Binary----> Decimal: Summation sum
Negative decimal----Negative binary:
Take absolute value
Convert to Binary
Take back plus 1
Negative binary----Negative decimal:
Minus 1 to reverse (or take counter plus 1)
Convert to decimal positive
Multiply-1
---> Binary
-123-->101
64+32+16+8+2+1
7<<2
(shift left) <<: Move left, a<<b:a b bit to the left, A<<b: The power of the formula A*2 B.
Signed right shift >>:a>>b:a move B bit right
Unsigned Right shift >>>:a>>>:a B-bit to the right, A>>>b formula: A/2 B Power
Example: 8>>>1 equivalent to 8/2 -7>>>2-->1073741822
Computer's binary:
1, Binary: Machine identification: 0 and 1 components
2, Decimal: Life, from 0 to 9 of the number composition
3, octal: from 0 to 7, every eight, borrow 1 top 8, required to start with 0
4, 16 binary: from 0 to 9 and a to F, requires starting with 0x
6. String Join operator: The result is a string +
Trinocular operator: X? Y:z;
If x is True then Y is selected and Z is selected if False.
Example 1:int num1=5,num2=3;
String result = num1>num2? " Really, ":" False?
Output: Really.
Example 2:system.out.println (false? ') A ': ' Z ');//z
int i= 2; 3>4?1.0*i/1:i/5;
The answer is: 5.0
int i = 2; 3>4?1.0*i/1:i/5;
The answer is: 0.0
Expression: A statement consisting of variables and operators in accordance with certain rules
Type of expression: is the data type of the result
The value of the expression: the result of an expression
Infer the value of an expression:
The values of the variables involved in each step are calculated by combining the priorities.
Tomorrow course:
Branch:
1, If-else
2. Switch
Homework Today:
1. It is known that m,n,k is an integer variable, what is the m,n,k after executing the following statement?
m = n = k = 8; M + = n + = k + = 1;
M =11; n = 10; K = 9;
2.int n = 5;n = ++n + + + + N; ask for n=?
N=13
3.int n = 3;n = ++n + n++; ask for n=?
N=8
4.int x = 4, y = 2, z = 3; What is the value of the expression y-=z++*--x?
What is the value of x, Y, z after the expression is run?
Value is: -7,x=3,y=-7,z=4
5. Please write out the output of the following expression:
int a = 11;
int b = 21;
Boolean ben1 = (--a)% (++b) <10 | (a++)/(b--)!=11 | (++a) * (--b) ==20 | (++a) < (--b);
System.out.println (ben1+ "\ t" +a + "\ T" +b);
True 13 19
Boolean ben2= (--a)% (++b) <10 | | (a++)/(b--)!=11 | | (++a) * (--b) ==20 | | (++a) < (--b);
System.out.println (ben2+ "\ t" +a + "\ T" +b);
True 11 21
6. Please calculate:
a=3,b=4;
(1):(a++)/3+ (--b) *2-(a--)%6+ (b++) *3-(b--)
3/3+3*2-4%6+3*3-4=1+6-4+9-4=8
A=3,b=4
(2):(++b) *2-(a--)%4+ (a++) *5-(--b)/2+ (--a)
5*2-3%4+2*5-4/2+2=10-3+10-2+2=17
A=3,b=4
(3):(a--) *6+ (b++)/3-(--a) *2-(--b) *2+ (++a)
3*6+4/3-1*2-4*2+2=18+1-2-8+2=11
Thousand Peaks training Day02-java Basic Learning: operator, binary conversion