Summary of knowledge from the past few days

1 Variable: A variable is a small box that holds data in memory, and you can only use it to store and retrieve data. Variables must have a clear type, what type of variable is loaded with what type of data. Variables cannot be defined repeatedly.

 

       

four categories

eight

number of bytes

Data representation range

Integer

byte

1

-128~127

short

2

-32768~32767

int

4

-2147483648~2147483648

long

8

-263~263-1

floating point

float

4

-3.403E38 ~3.403E38

double

8

-1.798E308 ~1.798E308

character type

char

2

Represents a character, such as ('a' , 'A', '0', 'home')

boolean

boolean

1

There are only two values ​​true and false

 

The smallest unit of information is called "bit (bit) The default floating point type in java is double type .

2 data type conversion:

A data type value with a small range (such as byte) can be directly converted to a data type value with a large range (such as int);

A data type value with a large range (such as int) cannot be directly converted to a data type value with a small range (such as byte)

byte < char < short < int < long < float< double

data type variable with large range = data type value with small range;

variable of data type  with small range = (data type with small range) value of data type with large range;

3 assignment operators

 * +=, -=, *=, /=, %=

 * The function of the above operator: Calculating the left and right sides of the equal sign will automatically convert the result to the data type on the left side of the equal sign, and then assign it to the data type on the left side of the equal sign

 * Note: The left side of the assignment operator must be a variable

 

4 Ternary operator: ( conditional expression) ? expression1:expression2;

Ternary operator operation rules: first determine the value of the conditional expression, if it is true, the result of the operation is expression1; if it is false, the result of the operation is expression2.

 

5   Operator precedence

  

priority

describe

operator

1

brackets

()[]

2

plus or minus sign

+-

3

Self-incrementing and self-decrementing, not

++--!

4

Multiply and divide, take remainder

*/%

5

Addition and subtraction

+-

6

shift operation

<<>>>>>

7

size relationship

>>=<<=

8

equality relation

==!=

9

bitwise AND

&

10

Bitwise XOR

^

11

bitwise OR

|

12

logical and

&&

13

logical or

||

14

conditional operation

?:

15

assignment operator

=+=-=*=/=%=

16

bit assignment operation

&=|=<<=>>=>>>=

 

6 Reference data type: data type  variable name = new data type ();

7 If statement refers to a certain processing if a certain condition is met.

 An if...else statement means that if a certain condition is met, a certain processing is performed, otherwise another processing is performed.

if...else if...else statements are used to judge multiple conditions and perform various processing.

The ternary operator will get a result, which is usually used to assign a value to a variable. When the judgment condition is satisfied, the result of the operation is the value of expression 1, otherwise the result is the value of expression 2.

8 while loop statement: The while statement will repeatedly judge the condition. As long as the condition is established, the execution statement in {} will be executed until the condition is not established, and the while loop ends.

9 for loop: The () after the for keyword includes three parts: initialization expression, loop condition and operation expression, which are separated by ";", and the execution statement in {} is the loop body.

10. Jump Statement: The break statement can be used in both the switch conditional statement and the loop statement. When it appears in a switch conditional statement, the effect is to terminate a case and jump out of the switch structure. When it appears in a loop statement, the function is to jump out of the loop statement and execute the following code. If the break statement jumps out of the outer loop, you need to add a marker to the outer loop.

The continue statement is used in the loop statement, its function is to terminate the current loop and execute the next loop.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326071007&siteId=291194637