# Small shoulder Android reverse -- 027-043

### 027. Arithmetic operators

1. Operator is a special symbol used to represent the operation, assignment and comparison of data.
2. +-When it exists as a cell operator, it indicates positive and negative
3. +When exists as a binary operator
+If there is no string on the left and right sides, the numerical operation is performed.
+If there are strings on the left and right sides, string splicing will be carried out. If it is not a string, it will be converted into a string.
```    System.out.println(100+98);//198
System.out.println('a'+1);//98
System.out.println("a"+1+3);//a13
System.out.println(1+3+"a");//4a
```
```    System.out.println(12/5);//2
System.out.println(12.0/5);//2.4
double a = 12/5; System.out.println(a);//2.0
int x = 4270; x = x / 1000 * 1000; System.out.println(x);//4000
```
A% B is equivalent to a - a / b * b
```    System.out.println(10 % 4);
```
It is used as an independent statement: the former + + and the latter + + are completely equivalent to i=i+1;
Use as an expression:
The first + + increases automatically before assignment (assignment is to assign to a temporary variable first)
After + + assign value first and then increase automatically
```    int i = 1; i = i++; System.out.println(i);
int i = 1; i = ++i; System.out.println(i);
int x = 4; int y = (--x)+(x--)+(x*10);
int i = 100; System.out.println(++i+i);
```
1. practice
43 days equals how many weeks and how many days
```public class Day {
public static void main(String[] args) {
int a = 43;
int weeks = 43/7;
int days = 43%7;
System.out.println(weeks + " "+days);
}
}

```
```4725 How many hours, minutes and seconds is a second equal to
```
```public class Seconds {
public static void main(String[] args) {
int a=4725;
int hours = a/(60*60);
int minutes = a/60-hours*60;
int seconds = a%60;
System.out.println(hours + " "+ minutes+" "+seconds);
}
}
```
```Centigrade temperature c ,Convert it to Fahrenheit f ,The conversion formula is: f=9/5*c+32
```
```public class Hua {
public static void main(String[] args) {
double c = 37;
double f = 9.0/5*c+32;//Don't write 9/5*c+32
System.out.println(f);
}
}
```

### 030. Assignment operator

1. The assignment operator is to assign the calculated value to the variable
2. The left side of the assignment operator can only be variables, and the right side can be variables, expressions and constants. The value on the right is assigned to the variable on the left.
3. Classification of assignment operators
Basic assignment operator=
int a = 100;
compound assignment operators
+= -= *= /= %=
a += 2; Equivalent to a = a + 2;
4. Interesting case
byte b = 3; b = b + 4; // wrong
byte b = 3; b += 4; // Yes, it is understood that there is a strong rotation process
byte b = 3; b++; // yes
byte b = 3; b = b + 1; // wrong

### 031. Relational operators

1. The results of relational operators (comparison operators) are boolean, that is, they are either true or false
2. Expressions composed of relational operators are called relational expressions. It is often used in the condition of if structure or the condition of loop structure
3. Relational operator
• ==Equal to don't write=
• != Not equal to
• < less than
• >Greater than
• < = less than or equal to
• >=Greater than or equal to
• A instanceof B indicates whether a is an object of class B

### 032. Logical operators

1. It is used to connect multiple relational expressions, and the final result is also a boolean value

2. Logical operator

• Logic and&
• Short circuit and&&
• Logical or|
• Short circuit or||
• Reverse!
• Logical XOR^
1. Logical operation rules
• A & b: when a and b are both true, the result is true; otherwise, it is false
• A & & b: when a and b are both true, the result is true; otherwise, it is false
• a|b: when one of a and B is true, the result is true, otherwise it is false
• A | b: when one of a and b is true, the result is true, otherwise it is false
• a^b: when a and b are different, the result is true; otherwise, it is false
• ! a: When a is true, the result is false. When a is false, the result is true
1. Difference between logic and short circuit
& Both sides operate whether true or false
&& The left is false, and the right is not calculated
| Both sides operate whether true or false
|| The left side is true, and the right side does not operate

### 034. Ternary operator

1. Basic grammar
Variable = (conditional expression)? Expression 1: expression 2;
Equivalent to the abbreviation of if...else... If the result of the conditional expression is true, expression 1 will be executed, and vice versa.
2. practice
```public class Max {
//Find the maximum of the three numbers
public static void main(String[] args) {
int a = 10;
int b = 20;
int c = 18;
int temp = a > b ? a : b;
int max = temp > c ? temp : c;
System.out.println(max);
}
}
```

### 035. Operation priority

```If you don't know the priority and want to ensure that the code runs without problems, you can add parentheses to change the priority
```

### 036. Base and bit operation

1. There are four representations of integers (characters can be converted into numbers according to the code table)
decimal system 0-9
Binary 0 starts with 1, 0b or 0b
octal number system 0-7, starting with 0
hexadecimal 0-9abcdef, starting with 0x or 0x

2. demonstration 3. Bitwise Operators
& | ^ ~ << >> >>>

### 037. Binary conversion

Divide the number by 16 until the quotient is 0. The remainder obtained in each step is inverted, which is the corresponding hexadecimal.
2. Binary to decimal
Starting from the low bit, convert the binary number into the corresponding hexadecimal number every four bits.
4. Hex coding
1 byte = 8 bit
Numbers in Java are signed

### 038.if

1. Three structures of program
• Sequential structure
• Branching structure
• Cyclic structure
1. Classification of branches
• Single branch if
When you swipe the bus card money < 10, you will be prompted that the balance is less than 10. Please recharge in time. Otherwise, no prompt will be given
• Double branch if...else ternary operation
When you swipe the bus card money > 2, it indicates that you swipe the card successfully. When money < 2, it indicates that the balance is insufficient
• Multi branch if...else if...else
1. The difference between continuous if and if... Else
2. if,switch,while,do...while,for
If only one statement is contained inside, you can omit the parentheses
3. Print the season of the month according to different defined months
```    int x = 3;
if(x>12 || x<1)
System.out.println("Month does not exist");
else if(x>=3  &&  x<=5)
System.out.println("spring");
else if(x>=6  &&  x<=8)
System.out.println("summer");
else if(x>=9  &&  x<=11)
System.out.println("autumn");
else
System.out.println("winter");
```

### 039.switch

1. Basic syntax of switch
Introduction to the functions of switch, case, break and default keywords
case and default are optional

2. Print the corresponding week according to the defined values

3. Generally, the order of case blocks can be reversed

5. Print the season of the month according to different defined months

```int x = 4;
switch(x){
case 3:
case 4:
case 5:
System.out.println("spring");
break;
}
```
1. The data type of the expression in switch should be consistent with the constant type after case, or it can be converted
2. The data types of expressions in switch can only be byte, short, char, int, String and enum
3. The value after case can only be a constant or a constant expression, not a variable

### 039.while

1. while basic syntax
Loop variable initialization
While (loop condition){
Execute statements;
Cyclic variable iteration
}
Judge first and then execute.

2. Execution process
Loop variable initialization
Judge cycle conditions
Execute statement
Cyclic variable iteration
Judge cycle conditions
......

3. do...while basic syntax
Loop variable initialization
do{
Execute statements;
Cyclic variable iteration
}While (cycle condition);
Loop first and then judge. It will be executed at least once.

### 042.for

1. for loop basic syntax
For (initialization expression; loop condition expression; operation expression after loop){
Execute statements;
}

2. Execution process of for loop
Initialization expression
Cyclic conditional expression
Execute statement
Operation expression after loop
Cyclic conditional expression
......

3. for loop considerations
The initialization expression and the operation expression after the loop can be written to other places, but the semicolon cannot be omitted
You can put any expression, but the loop condition expression must return boolean type
The initialization expression and the operation expression after the loop can put multiple expressions and connect them with commas
A variable has its own scope. For for: if a variable is defined in a for statement, the variable is only valid in a for statement. After the for statement is executed, the variable is released in memory

### 043.break and continue

For an example, understand break, continue and return

```public class BreakContinueReturn {
public static void main(String[] args) {
for (int i = 0; i < 10; i++) {
if(i==2){
break;
//                continue;
//                return;
}
System.out.println(i);
}
System.out.println("This is the statement of extracorporeal circulation");
}
}
```

Posted by jogisarge on Wed, 03 Nov 2021 09:52:07 -0700