The operator
Arithmetic operator:
+ – * / % ++ —
Key points: + +
When ++ is finished, it will automatically add 1, whether it appears before or after the variable.
int i = 10; i++; System.out.println(i); // 11 int k = 10; ++k; System.out.println(k); Int I = 10; // int I = 10; int k = ++i; System.out.println(k); // 11 System.out.println(i); Int I = 10; // int I = 10; int k = i++; System.out.println(k); // 10 System.out.println(i); // 11 int i = 10; System.out.println(i++); // 10 What is the trick to solving the above problems? Int temp = i++; System.out.println(temp); // 10 System.out.println(i); // 11 int i = 10; System.out.println(++i); Int temp = ++ I; System.out.println(temp); // 11 System.out.println(i); / / 11
Relational operator:
> >= < <= == !=
They all turn out to be Boolean. true/false
Logical Operator:
& | ! && ||
A logical operator requires that both sides be Booleans and that the final result be Booleans.
Boolean on the left & Boolean on the right -> is still Boolean.
&if both sides are true, the result is true
| side is true, the result is true
! The not
The result of am& and am& is exactly the same, except that am& has a short circuit.
When the left is false: && is short-circuited.
On the left is true: | | short circuit.
Assignment operator:
= += -= *= /= %=
Important rules:
When using the extended assignment operator, be careful that no matter how you perform the operation, the resulting type of the operation will not change.
byte x = 100; // byte maximum 127 x += 1000; // Compilation works. The x variable is still a byte type, but the accuracy is lost. x += 1000; Equivalent to: x = (byte)(x + 1000); int i = 10; i += 10; I = I + 10; Accumulation.
The ternary operator:
Boolean expression? Expression 1: Expression 2
The Boolean expression is true, and select expression 1 as the result.
Instead, select expression 2 as the result.
String concatenation operator:
+
Plus, I have numbers on both sides, and I sum them up.
+ one side is a string, string concatenation.
+ If there are more than one, follow the sequence from left to right: 1 + 2 + 3
If you want one of the plus signs to run first, you can add parentheses: 1 + (2 + 3)
Note: after concatenation, the result is still a string.
Tip: how to insert a variable into a string.
String name = "jackson"; System.out.println(" Login successfully, welcome "+name+" back ");
How to receive user keyboard input?
java.util.Scanner s = new java.util.Scanner(System.in); // receive int I = s.nextInt() // receive String STR = s.next();
The last
Recommend to you a more detailed Java zero based tutorial, the following is what I have seen feel quite good, worth watching the collection.
To share with you, click here
https://www.bilibili.com/vide…
If it helps you, thank thumb up for your support