First, basic if structure
1. Flowchart
Input/Output
Judging and branching
Process Line
1.1 Simple if condition to judge
if ( expression ) {
// expression is true , execute the code in {}
}
1.2 Simple if condition to judge
if ( expression ) {
// expression is true , execute here
}else{
// expression is false , this line here
}
Description: If the If or else is followed by, and there is only one line of code, {} can be omitted, but it is not recommended to omit
Second, logical operators
L && Logic and (press shift+7)--and (and, at the same time)
Multiple conditions, 1 are false, if () all false, multiple conditions are true at the same time, if () is true
L | | (Press shift+ to enter the above |) -or (OR)
Multiple conditions, as long as 1 are true, if () all is true
! (in English state)--take the inverse not equal to! =
L determine if strings are equal
A , case-sensitive: password
String Variables . Equals ( the value of a string or a string variable )
B , Case insensitive: Verification Code
String Variables . Equalsignorecase ( value of string or string variable )
How do I break down numbers in bits, 10, hundred, thousand? "P47"
Int digit = number% 10//decomposition get single digit
Int 10 bit = number/10 10//decomposition get 10 digits
Int hundred = number/100% 10//decomposition to get the number of hundred
INT thousand = number/1000% 10//Decomposition get thousand
Third, multiple if structure
if (condition 1) { //code block}else if (condition 2) {//code block}else if (condition N) { //code block} else{ //code block}
Description: An else if can have multiple, sequential requirements on the number range
in the if input string--if (variable name. Equals ("string")) {}
Iv. Nested IF structures
if (condition 1) { //code block I f (condition 1-1) { } Description: The If structure can be an if, if...else, multiple if structure} else{can be if, if...else, multiple if and other structures}
V. Syntax for switch structure (switching statements)
5.1 Switch structure use:
int \char 2 Types of equivalence judgment to use
5.2. Switch structure and if structure similarities and differences
Same point: equal judgment can be achieved
Different points:
1. Different syntax
2. The use of different occasions
3. If structure, focusing on range judgment
4. Switch structure, focusing on equivalence judgment, type can only be int, char type
5. Efficiency:
In the equivalence judgment, the switch structure efficiency is higher than the IF structure
Vi. exception handling--hasnextint ();
Determines whether an integer
if (Input.hasnextint ()) {//Boolean type
code block
}
Java Basics (3)