Fourth Chapter
The syntax of a switch structure (switching statement)
switch (expression [dream1]) {
Case constant 1[DREAM2]:
Statement Block 1
BREAK[DREAM3];
Case constant N[DREAM4]:
Statement block N
Break
DEFAULT[DREAM5]:
Statement block
Break
}
Second, switch structure use occasions: int \char 2 types of equivalence judgment to use
Iii. the similarities and differences between switch structure and if structure
Same point: equal judgment can be achieved
Different points:
L syntax is different
L use different occasions.
n if structure, focusing on range judgment
N-switch structure, focusing on equivalence judgments, types can only be int, char type
L Efficiency
N in the equivalence judgment, the switch structure efficiency is higher than the IF structure
Iv. exception handling--hasnextint ();
Determines whether an integer
if (Input.hasnextint ()) {//Boolean type
code block
}
Fifth Chapter
First, commissioning
Step 1: Set a breakpoint (you cannot set a breakpoint in an empty space)
Step 2: Start debugging
Step 3: Debug code (F6 Single Step) notebook Fn+f6 (F5)
Step 4: End Debugging
Mastering the benefits of debugging?
l See clearly, the order in which the code executes
L quickly navigate to where the exception code appears and help modify or improve the code
Second, while loop
1, the advantages of the cycle?
Reduce the coding of repetitive code, the program will be more concise
2. Grammar
while (expression) {
1. The expression is a "loop condition" and the result must be a Boolean type
2, the code in {}, that is, "loop operation (body)"
3. "Iteration section" changes the loop condition to end the loop
}
3, Characteristics: First judge, then execute
4. While loop has 2 common ways
Mode 1: "P98 page--Example code 5"
while (1, loop condition: Determines whether strings are equal) {
2. Cyclic operation
3. Receive the string in the keyboard again, change the loop condition, to end the loop
}
Method 2: "P97 page Example 4 code"
while (1, loop condition: int variable combined with relational operator for comparison) {
2. Cyclic operation
3, iteration part, int variable + + or--, to change the loop condition, end the loop operation
}
Third, Do....while cycle
1, applicable occasions: first cycle 1 times, according to the conditions of judgment, recycling
2. Grammar
do{
2. Circulating body (cyclic operation)
3. Change the cycle condition
}while (conditions); 1. Cyclic conditions
Java (chapters fourth and fifth)