1. Basic usage of logical operators, what are logical operators:
&,|,^,!,&&,| |
Caveats: Logical operators are typically used to concatenate expressions or values of type Boolean.
Expression: Is the Java syntax that is used to concatenate constants or variables with an operator.
Arithmetic expression: A + b
Comparison expression: a = = B (conditional expression)
Conclusion:
& Logic with: False if False.
Logical OR: TRUE if true.
Logical XOR: The same is false, and the difference is true.
The logical non: false is true, and false if not true.
Features: An even number does not change itself.
2. The difference between logical operators && and &
The difference between && and &:
The end result is the same. && has short circuit effect. The left side is false and the right side is not executed. && 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.
&,|,^,~,>>,>>>,<<
3. Characteristics of bitwise XOR OR operator:
Characteristic: One data is different to another data bit or two times, the number itself is unchanged.
Basic usage of bitwise operators:
Usage of >>,>>>,<<:
<<: Left highest bit discarded, right 0
>>: The right shift is 0, the left side is 0, the maximum is 1, the left side is 1
>>>: Unsigned right shift whether the highest bit is 0 or 1, the left side is 0
4, the basic usage of ternary operators;
The format of the ternary operator;
(Relational expressions)? Expression 1: Expression 2;
How to realize the keyboard input it;
Take the format first.
Guide Package
Format:
Import Java.util.Scanner;
Position:
Above the class.
To create a keyboard entry object:
Format:
Scanner sc = new Scanner (system.in);
Getting data from objects
Format:
int x = Sc.nextint ();
5. Sequential Structure statement:
What is a Process Control statement
Process Control statement: The execution flow of the program can be controlled.
Classification of Process Control statements:
Sequential structure
Select structure
Loop structure
Execution process:
From the top down, execute in turn.
If statement
Switch statement
The value of the comparison expression is evaluated first to see if its return value is true or false.
If true, the statement body is executed;
If False, the statement body is not executed;
Select Structure If statement considerations * A: Case Presentation
The comparison expression is either simple or complex, the result must be a Boolean type
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.
Generally speaking: there is no semicolon on the left curly brace, there is no left brace for the semicolon
Select nested use of the structure if statement:
Format of the Select Structure switch statement and its interpretation * A:switch statement format
switch (expression) {
Case value 1:
Statement body 1;
Break
Case Value 2:
Statement body 2;
Break
...
Default
Statement body n+1;
Break
}
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
Considerations for choosing a structure switch statement
A case can be followed only by a constant, not a variable, and the value after multiple occurrences cannot appear the same
Can default be omitted?
It can be omitted, but it is not recommended, because it is used to prompt for incorrect conditions.
Special cases:
case, you can fix the value.
A,b,c,d
Can break be omitted?
The last one can be omitted, the other best not to omit
There is a phenomenon: case penetrating.
It is recommended not to omit
Must the default be at the end?
No, it can be anywhere. But the suggestion at the end.
End condition of the switch statement:
It's over when we hit the break.
The closing curly brace to switch is over.
Java Language Basics 2