# # #03.01_java Language Basics (Basic usage of logical operators) (master)
* A: What are logical operators
* &,|,^,! Logic and & Logic or | Logical XOR ^ logical non!
* &&,| | Logic double and && logic dual or | |
* B: Case Demo
* Basic usage of logical operators
* int a = 10;
* int b = 20;
* System.out.println (A > & a > 0); True + True if True has false then false
* System.out.println (A > | a > 0); True + True if True is True
* System.out.println (A > Ten ^ a > 0); True + True if False is the same false is true
* SYSTEM.OUT.PRINTLN (!ture); Output is False
*
* Precautions:
* A: Logical operators are typically used to concatenate expressions or values of type Boolean.
* B: expression: It is the Java syntax that joins a constant or variable with an operator.
* Arithmetic expression: A + b
* Comparison expression: a = = B (conditional expression)
* C: Conclusion:
* & Logic with: false is false.
* | Logical OR: TRUE if true.
* ^ Logical XOR: The same is false, and the difference is true.
* Logical non: false is true, False if not true.
* Features: An even number does not change itself.
# # #03.02_java Language Basics (logical operators && and & Differences) (Master)
* A: Case Presentation
* The difference between && and &?
* A: The end result is the same.
* b:&& has short circuit effect. The left side is false and the right side is not executed.
* & whether the Left is false or true, the right side will execute
* int i = 4;
* int y = 5;
* SYSTEM.OUT.PRINTLN ((++i > 5) && (++y > 6)) The output is i = 5 y = 5 because the left is false to the right does not execute
* B: similarly | | and | The difference? (Student self-study)
* C: Who is used in development?
* &&,| |,!
# # #03.08_java Language Basics (Basic format for keyboard entry) (master)
* A: Why use the keyboard to enter data
* A: To make the program's data more consistent with the developed data
* B: Make the program more flexible
* B: How to implement keyboard input?
* Format first.
* A: Guide package
Format
* Import Java.util.Scanner;
Location
* Above class.
* B: Create keyboard Entry Object
Format
* Scanner sc = new Scanner (system.in);
* C: Get data from objects
Format
* int x = Sc.nextint ();
* C: Case Demo
* Keyboard input 1 integers, and output to the console.
* Keyboard input 2 integers, and output to the console.
Scanner sc = new Scanner (system.in)
int a = Sc.nextint ();
int b = Sc.nextint ();
# # #03.12_java Language Foundation (SELECT Structure if statement format 1 and use) (master)
* A: Select the classification of the structure
* If statement
* Switch statement
* B:IF statements are available in several formats
* Format 1
* Format 2
* Format 3
* Format of the C:IF statement 1
*
if (comparison expression) {
Statement body;
}
* D: Execution Process:
* The value of the comparison expression is evaluated first to see if its return value is true or false.
* If true, executes the statement body;
* If False, the statement body is not executed;
# # #03.13_java Language Basics (SELECT Structure if statement considerations) (Master)
* A: Case Presentation
* A: Compare expressions whether simple or complex, the result must be a Boolean type
* B:IF Statement Control Statement Body if it is a statement, curly braces can be omitted;
* If it is more than one statement, you cannot omit it. Never omit the suggestion.
* C: Generally speaking: there is no semicolon on the left curly brace, there is no left brace for the semicolon
# # #03.14_java Language Foundation (SELECT Structure if statement format 2 and use) (master)
* Format of the A:IF statement 2
*
if (comparison expression) {
Statement body 1;
}else {
Statement body 2;
}
* B: Execution Process:
* The value of the comparison expression is evaluated first to see if its return value is true or false.
* If true, executes the statement body 1;
* If False, executes the statement body 2;
* C: Case Demo
* A: Get a larger value from two data
* B: Determine whether a data is odd or even, and whether the output is odd or even
if (a% 2 ==0) {
System.out.println ("even");
}else{
System.out.println ("odd");
}
* Note: Else there is no comparison after the expression, only if there is.
# # #03.15_java Language Foundation (if statement format 2 and ternary conversion problem) (master)
* A: Case Presentation
* If statement and ternary operator complete the same effect
* B: Case Demo
* The difference between an if statement and a ternary operator
* Ternary operators can be implemented using the IF statement. Conversely, it is not established.
* When does the IF statement implementation not use ternary improvement?
* Cannot when the IF statement control operation is an output statement.
* Why? Because the ternary operator is an operator, the operator should have a result, rather than an output, after the operation.
# #03.16_java Language Basics (SELECT Structure if statement format 3 and use) (master)
* Format of the A:IF statement 3:
*
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 evaluates the comparison expression 1 to see if its return value is true or FALSE,
* If true, executes the statement body 1,IF statement end.
* If False, then the comparison expression 2 is evaluated to see if the return value is true or FALSE,
* If true, executes the statement body 2,IF statement end.
* If False, then the comparison expression 3 is evaluated to see if the return value is true or FALSE,
* If all is false, execute the statement body n+1.
* C: NOTE: The last else can be omitted, but it is not recommended to omit, you can prompt for error values outside the range
# # #03.19_java Language Basics (format of the Select Structure switch statement and its interpretation) (master)
* Format of the A:switch statement
*
switch (expression) {
Case value 1:
Statement body 1;
Break
Case Value 2:
Statement body 2;
Break
...
Default
Statement body n+1;
Break
}
* Format explanation of the B:switch statement
* C: Face question
* Can byte be used as a switch expression?
* Can long be used as a switch expression? No, you can.
* Can string be used as a switch expression?
* Before JAVA7, switch can only support byte, short, char, int or its corresponding wrapper class and enum type. In Java7, a string type is also supported.
* C: Execution process
* Evaluates the value of an expression first
* Then match the case, and execute the corresponding statement if there is one, otherwise execute the default control statement
# # #03.20_java Language Basics (exercises to select structure switch statements) (master)
* A: Integer (given a value, the output corresponds to the day of the week)
# # #03.21_java Language Basics (Considerations for choosing a structure switch statement) (master)
* A: Case Presentation
* A:case can only be a constant, cannot be a variable, and the value after multiple case cannot appear the same
* Can B:default be omitted?
* Can be omitted, but is not recommended, because its role is to give a hint to the incorrect situation.
* Special case:
* Case can fix the value.
* A,b,c,d
* Can c:break be omitted?
* The last one can be omitted, the other best not to omit
* There is a phenomenon: case penetrating.
* Finally we recommend not to omit
* D:default must be at the end?
* No, it can be anywhere. But the suggestion at the end.
* End condition of E:switch statement
* A: It's over when you hit a break
* B: Execution to switch closing curly brace is over.
* A: Summarize the respective usage scenarios for the switch statement and the IF statement
* switch is recommended for determining fixed values
* If it is recommended to determine the interval or range of time with
Java Note 03th