Basic usage of JAVA logical operators

###03.01_Java language basics (basic usage of logical operators) (master)
* A: What are the logical operators
* &,|,^,!
* &&,|| 
* B: Case demonstration
* The basics of logical operators Usage * Notes: * a: Logical operators are generally used to connect expressions or values ​​of boolean type. * b: expression: It is a formula that conforms to java syntax by connecting constants or variables with operators. * Arithmetic expression: a + b * Comparison expression: a == b (conditional expression) * C: Conclusion: * & Logical AND: false if there is false. * | Logical OR: true if there is true. * ^ Logical XOR: same as false, different as true. * ! Logical NOT: true if not false, false if not true. * Features: Even number does not change itself. ###03.02_Java language foundation (the difference between logical operators && and &) (master) * A: case demonstration * The difference between && and &? * a: The final result is the same. * b:&& has a short-circuit effect. The left is false, the right is not executed. * & is whether the left side is false or true, the right side will be executed * B: The difference between || and |






















* &&,||,!


###03.03_Java language basics (basic usage of bitwise operators 1) (understand)
* A: What are the bitwise operators
* &,|,^,~ ,>>,>>>, <<
* B: Case demonstration
* Basic usage of bitwise operators 1 * &,|,^,~ Usage * &: 0 if there is 0 * |: 1 if there is 1 * ^: same as 0, different if 1 * ~: Bitwise negation ###03.04_Java language basics (characteristics of the bitwise XOR operator and interview questions) (master) * A: Case demonstration * Features of the bitwise XOR operator * ^ Features: one data to another A data bit is XORed twice, the number itself is unchanged. * B: Interview questions: * Please implement the exchange of two integer variables by yourself * Note: In the process of lectures later, I did not specify the type of data clearly, the default type is int. ###03.05_Java Language Basics (Basic Usage of Bit Operators 2 and Interview Questions) (Understanding) * A: Case Demonstration >>, >>>, << Usage: * <<: Left shift, the left most significant bit is discarded, The right is filled with 0 * >>: The highest bit is 0, and the left is filled with 0; the highest is 1, and the left is filled with 1 * >>>:




























###03.06_Java language foundation (basic usage of ternary operator) (master)
* A: Format of ternary operator
* (relational expression) ? Expression 1 : Expression 2;
* B: Ternary operator Execution process 
* C: Case demonstration
* Get the maximum value of two numbers


###03.07_Java language foundation (ternary operator practice) (master)
* A: Case demonstration
* Compare two integers to see if they are the same
* B: Case demonstration
* Get the maximum value of three integers


###03.08_Java language basics (explain the basic format of keyboard input) (master)
* A: Why use the keyboard to input data
* a: In order to make the data of the program more in line with the development Data
* b: Make the program more flexible
* B: How to realize keyboard input?
* Follow the format first.
* a: import package
* Format:
* import java.util.Scanner; 
* Location:
* Above the class.
* b: Create keyboard entry object
* Format:
* Scanner sc = new Scanner(System.in);
* c: Get data through object * Format:

* int x = sc.nextInt();
* C: case demonstration
* Input an integer with the keyboard and output it to the console.
* Input 2 integers on the keyboard and output to the console.


###03.09_Java Language Basics (Keyboard Entry Exercise 1) (Mastery)
* A: Case Demonstration
* Keyboard Entry Exercise: Keyboard entry two data, sum the two data, and output the result
* B: Case demonstration
* Keyboard input exercise: keyboard input two data, get the maximum value of these two data


###03.10_Java language basics (keyboard input exercise 2) (master)
* A: case demonstration
* Keyboard input exercise: keyboard input two two data, compare whether the two data are equal
* B: case demonstration
* keyboard input exercise: keyboard input three data, get the maximum value of the three data


###03.11_Java language foundation (sequential structure statement) (understand)
* A: What is a flow control statement
* Flow control statement: It can control the execution flow of the program.
* B: Classification of flow control statements
* Sequence structure
* Selection structure
* Loop structure
* C: Execution flow:
* Execute sequentially from top to bottom.
* D: Case demonstration
* Just output a few sentences to see the effect


###03.12_Java language foundation (choose structure if statement format 1 and its use) (master)
* A: Classification of selection structures
* if statement
* switch statement
* B: There are several formats of if statement
* Format 1
* Format 2
* Format 3
* C: Format 1 of if statement

if(comparison expression) {
statement body;
}
* D: Execution process:
* Calculate the value of the comparison expression first to see if its return value is true or false.
* If it is true, execute the statement body;
* If it is false, do not execute the statement body;


###03.13_Java language foundation (precautions for selecting structure if statement) (master)
* A: case demonstration
* a: comparison expression Whether simple or complex, the result must be a boolean type
* b: If the statement body controlled by the if statement is a single statement, the curly braces can be omitted;
  * If it is multiple statements, it cannot be omitted. It is recommended to never omit.
* c: Generally speaking: there is no semicolon if there is an opening brace, and there is no opening brace if there is a semicolon


###03.14_Java language basics (choose structure if statement format 2 and its use) (master)
* A:if statement Format 2

if(comparison expression) {
statement body 1;
}else {
statement body 2;
}
* B: Execution process:
* First calculate the value of the comparison expression to see if its return value is true or false.
* If it is true, execute statement body 1;
* If it is false, execute statement body 2;
* C: case demonstration
* a: get the larger value of two data
* b: determine whether a data is odd or even, And output is odd or even


* Note: There is no comparison expression after else, only after if.


###03.15_Java language foundation (form 2 of if statement and ternary conversion problem) (master)
* A: case demonstration
* if statement and ternary operator accomplish the same effect
* B: case demonstration
* if statement and The difference between the ternary operator * The ternary operator can be implemented by using the if statement. The opposite does not hold. * When can the if statement implementation not be improved with ternary? * Not when the operation controlled by the if statement is an output statement. * Why? Because the ternary operator is an operator, the operator should have a result after the operation is completed, not an output. ###03.16_Java language foundation (choose structure if statement format 3 and its use) (master) * A: Format 3 of if statement: if (comparison expression 1) { statement body 1; }else if (comparison expression 2) { statement body 2; }else if(comparison expression 3) {
















Statement body 3;
}
...
else {
Statement body n+1;
}
* B: Execution process:
* First calculate the comparison expression 1 to see if its return value is true or false,
* If it is true, execute statement body 1, The if statement ends.
* If it is false, then calculate the comparison expression 2 to see if its return value is true or false, * If it is true, execute statement body 2, and the if statement ends. * If it is false, then evaluate the comparison expression 3 to see if its return value is true or false, * If both are false, execute the statement body n+1. * C: Note: The last else can be omitted, but it is recommended not to omit it, you can prompt for error values ​​outside the range  ###03.17_Java language foundation (choose structure if statement format 3 exercises) (master) * A: Exercise 1 Requirement: Input a grade on the keyboard, judge and output the grade of the grade. 90-100 Excellent 80-89 Good 70-79 Medium 60-69 and 0-59 Poor * B: Exercise 2 * Requirements: * Input the value of x on the keyboard, calculate and output the value of y. * x>=3 y = 2 * x + 1; * -1<x<3























y = 2 * x;
* x<=-1 y = 2 * x - 1;


###03.18_Java language foundation (choose the nested use of structural if statements) (master)
* A: case demonstration
* Requirement: get three Maximum value in data
* Nested use of if statements.


###03.19_Java Language Fundamentals (Format of Choice Structure Switch Statement and Its Interpretation) (Mastery)
* A: Format of switch statement

switch(expression) {
      case value 1:
statement body 1;
break;
    case value 2:
statement body 2;
break;
    …
    default: statement body n+1; break;     } * B: Explanation of the format of switch statement * C: Interview question * Can byte be used as the expression of switch? * Can long be used as the expression of switch? * Can String be used as the expression of switch? * C: Execution flow * Calculate the value of the expression first



 







* Then match with the following case, if there is, execute the corresponding statement, otherwise execute the statement controlled by default


###03.20_Java language foundation (choose the exercise of structural switch statement) (master)
* A: integer (given a value, The output corresponds to the day of the week)


###03.21_Java language basics (precautions for selecting structural switch statements) (master)
* A: case demonstration
* a: case can only be followed by constants, not variables, and, after multiple cases Values ​​cannot appear the same
* b:default can be omitted?
* can be omitted, but it is not recommended, because its role is to give a hint to the incorrect situation.
* Special cases:
* case can fix the value.
* Can A, B, C, D
* c:break be omitted?
* The last one can be omitted, and the others should not be omitted
* There will be a phenomenon: case penetration.
* Finally we recommend not to omit
* Does d:default have to be at the end?
* No, it can be anywhere. But advice is at the end.
* e: End condition of switch statement
* a: It ends when break is encountered
* b: Executes to the closing brace of switch and ends


###03.22_Java language basics (choose structural switch statement practice) (master)
* A: Look at the program write result:

int x = 2;
int y = 3;
switch(x){
default:
y++;
break;
case 3:
y++;
case 4:
y++;
}
System.out.println("y="+y); * B: see the program write result: int x = 2; int y = 3; switch(x){ default: y++; case 3: y++; case 4: y++; } System.out.println("y="+y); ###03.23_Java Basics (the difference between selection structure if statement and switch statement) (master) * A: Summarize the respective usage scenarios of switch statement and if statement * switch is recommended to use when judging fixed values ​​* if is recommended to use when judging intervals or ranges * B: Case Demonstration * Use switch statement and if statement respectively to achieve the following requirements: * Input the month on the keyboard and output the corresponding season



























Guess you like

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