This is the second day of my participation in the November Gwen Challenge. Check out the details: the last Gwen Challenge 2021

Hi, I’m Ken

Hereby declare that it shall not be reproduced without permission

📚 operator.

📌 arithmetic operators (+, -, *, /, %)

Important: whether ++ ++ appears before or after a variable, it will automatically increment by 1 after the operation.

📌 increment and decrement operators

The increment and decrement operators (+, -), ++, and – are unary operators and can be placed before or after operands. The operand must be an integer or floating-point variable that increases or decreases the value of the variable by one. The difference between ++x and x++ is that ++x executes x=x+1 before using the value of x, whereas x++ executes x=x+1 after using the value of x.

// 
int i = 10;
i++;
System.out.println(i); / / 11

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

int i = 10;
System.out.println(++i); / / 11
// Unpack code:
int temp = ++i;
System.out.println(temp); / / 11
System.out.println(i); / / 11

// 原文出自: CSDN-请叫我阿ken
Copy the code

📌 relational operators (>, >=, <, <=, ==,! =)

Results of relational operators are Boolean (true/false)

📌 logical operators (&, |,! , &&, | |)

A logical operator requires that both sides be Boolean and that the final result is still Boolean. & is true on both sides, the result is true | side is true, the result is true! In fact, the inverse && and & operation results are exactly the same, the difference lies in: && there is a short circuit phenomenon. When the left side is false: && short-circuited. On the left is true: | | short circuit.

📌 assignment operators (=, +=, -=, *=, /=, %=)

Important rule: When using extended assignment operators, note that the type of the final result does not change.

byte x = 100; // byte The maximum value is 127
x += 1000; // The compilation can pass, the x variable is still byte, but the precision is lost.

x += 1000; Equivalent to: x = (byte)(x + 1000);
int i = 10;
i += 10; // same as: I = I + 10; Accumulation.

// 原文出自: CSDN-请叫我阿ken
Copy the code

📌 conditional operator

Ternary operator syntax: Boolean expressions? Expression 1: The Boolean expression of expression 2 is true, and expression 1 is selected as the result. Instead, choose expression 2 as the result.

📌 string concatenation operator

+… 1+ 2+3 If you want one of the plus signs to be executed first, you can add parentheses: 1+ (2+3) note: the result of the concatenation of strings is still a string.

Tip: How to squeeze a variable into a string.

String name = "jackson"; System.out.println("Welcome to a successful landing."+name+"Come back");

// 原文出自: CSDN-请叫我阿ken
Copy the code

📌 bit operator

Integer data is represented in binary form in memory. For example, a variable of type int takes up 4 bytes in memory and contains 32 bits. The binary representation of type int 7 is:

00000000 00000000 00000000 00000111
Copy the code

The highest bit on the left is the sign bit. The highest bit is 0 for a positive number and 1 for a negative number. Negative numbers are represented by complement. For example, the complement of -8 is:

The complement, source, and inverse of positive numbers are the same. The complement of +8, the original, the inverse, is 0000, 1000. The complement, source and inverse of negative numbers are all placed in the sign bit with 1, and the following 7 bits are changed: the source of -8:1000, 1000; The inverse of -8:1111 0111; The complement of -8:1111 1000. // Please call me KenCopy the code

!!!!!!!!!!

📌 instanceof operator

This operator is a binocular operator. The operand on the left is an object and on the right is a class. This operator returns true if the object on the left is created by a class or subclass on the right, false otherwise (more on that later)

📌switch Switch statement

switch(expression){caseConstant values1; Several statementsbreak;

caseConstant values2; Several statementsbreak; .caseConstant value n. Several statementsbreak;

default; Several statements}// The switvh expression can be byte, short, int, or char. Constants from 1 to n are also of byte, short, int, and char, and may differ from each other.

// 原文出自: CSDN-请叫我阿ken
Copy the code

📚 loop statement

📌 while loop

  • Its syntax mechanism and execution principle: while (Boolean expression) {

    The loop body. } If the Boolean expression is true, the loop body is executed. After the loop body is finished, the result of the Boolean expression is judged again. If it is still true, the loop body is executed again.

  • Case loop:

while(true){
System.out.println("Dead loop");
}

// 原文出自: CSDN-请叫我阿ken
Copy the code

Control statements

  1. About loop statements for loop, while loop, do… While loop What is a loop statement and why do we use it? Because in the real world, there are many things that need to be done over and over again. To reduce the amount of code, use loop statements.

Requirements: First point: you must learn the grammatical structure by heart. Number two: you have to understand how they work. To implement cases, to implement features. Start with simple cases and work your way through the complex problems.

📌 do… The while loop

do{circulatory body; }while(Boolean expression);/* This last semicolon is crucial */

// 原文出自: CSDN-请叫我阿ken
Copy the code

How it works: Execute a loop statement, then judge a Boolean expression, if true continue execution, if false stop loop.

int i = 0;
do{
System.out.println(i); // 0 1 2 3... 8 and 9
i++;
// We can replace the previous two lines with
// System.out.println(i++);
}while(i < 10);

int i = 0;
do{
System.out.println(++i); // 1 2 3... 8 9 10
}while(i < 10);

int k = 100;
System.out.println(++k); / / 101
System.out.println(k);   / / 101

int m = 10;
System.out.println(m++); / / 10
System.out.println(m)    / / 11

// 原文出自: CSDN-请叫我阿ken
Copy the code

Turn statements: break, continue, return (more on this later when sorting into methods)

📌for loop statement

for(expression1; expression2; expression3) {loop statement; }// 原文出自: CSDN-请叫我阿ken
Copy the code
// anli
public class Example_n {
public static void main(String args[]){
long sum = 0, a = 8, item = a, n = 12, i = 1;
for(i = 1; i <= n; i++) {
sum = sum + item;
item = item*10+ a; } System.out.println(sum); }}// 原文出自: CSDN-请叫我阿ken
Copy the code

If and switch are branch statements and select statements (select structures). For, while, do… While… These are loop statements (loop structures). Break, continue, and return belong to the turn structure. For and while are completely interchangeable except in different syntax.

🌊 Give back to fans

Follow the public account “Please call me Ken” to share two quality Java e-books randomly

Thanks for reading. I’m Ken