The operator

Arithmetic operators:

+ - * / % ++ --

Key points: + +

Whether the ++ appears before or after the variable, as soon as the ++ operation is over, it will automatically add 1.

int i = 10; i++; System.out.println(i); // 11 int k = 10; ++k; System.out.println(k); // 11 ++ appears before variable: int I = 10; int k = ++i; System.out.println(k); // 11 System.out.println(i); // 11 ++ appears after variable: 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 solve 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); / / 11Copy the code

Relational operators:

> >= < <= == !=

They all turn out to be Boolean types. true/false

Logical operators:

& | ! && ||

Logical operators require both sides to be Boolean, and the end result to be Boolean.

The left is a Boolean type & the right is a Boolean type -> The end result is still a Boolean type.

&if both sides are true, the result is true

| side is true, the result is true

! The not

In fact, the result of && is exactly the same as that of &, except that there is a short circuit in &&.

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 aware that no matter how the operator operates, the type of the result will not change.

byte x = 100; // byte Max. 127 x += 1000; // The compiler can pass. The x variable is still byte, but the accuracy is lost. x += 1000; X = (byte)(x + 1000); int i = 10; i += 10; // equivalent to: I = I + 10; Accumulation.Copy the code

Ternary operators:

Boolean expression? Expression 1: Expression 2

Boolean expression is true and select expression 1 as the result.

Instead select expression 2 as the result.

String concatenation operator:

+

Plus numbers on both sides, sum over.

+ One side is a string, to concatenate the string.

If there are more than one +, execute from left to right: 1 + 2 + 3

If you want one of the plus signs to execute first, you can add parentheses: 1 + (2 + 3)

Note: The result of concatenation is still a string.

Tip: How to cram a variable into a string.

String name = "jackson"; System.out.println(" login successful, welcome "+name+" back ");Copy the code

How do I receive user keyboard input?

java.util.Scanner s = new java.util.Scanner(System.in); // Receive int I = s.ext () // receive String STR = s.ext ();Copy the code

The last

Recommended to you a more detailed Java zero basic tutorial, the following is I have seen feel pretty good, worth watching the collection.

To share it with you, click here

www.bilibili.com/video/BV1Rx…

If it helped you, thank you for your support