1: Switch statement (master) (1) Format:Switch(expression) { Casevalue 1: statement body 1; Break; Casevalue 2: statement body 2; Break; ... default: statement body n+1; Break; } Format Explanation:Switch: Description This is a switch statement. Expression: Can be a byte, Short,int,CharJDK5 can be after enumeration JDK7 can be a string later Case: The value that follows is the value to compare to the expression Break: Indicates that the program is interrupted here and jumps out of the switch statementdefault: If all the cases do not match, execute here, equivalent to the else in the IF statement (2) The expression for the question switch statement can be a byte, notCan be a long,after JDK7can be a string
(3The execution process: A: First evaluates the value of the expression B: matches each case, if any, executes the corresponding statement body, see break ends. C: If there is no match, execute the default statement body N+1. (4Note: A:case can only be a constant, cannot be a variable, and the value after multiple case cannot appear the same b:default can be omitted?it can be omitted, but it is not recommended, because it is used to prompt for incorrect conditions. Special situation: Case can fix the value. Can a,b,c,d c:break be omitted??can be omitted, but the result may not be what we want. There is a phenomenon: case penetrating. Finally we suggest not to omit D:default must be at the end?No, it can be anywhere. But the suggestion at the end. The end condition of the E:switch statement a: It ends when a break is encountered B: Execution ends at the end (5) Case: A: Keyboard input a number (1-7), the output corresponds to the day of the week. B: Single-choice question C: keyboard input A string of questions string s=Sc.nextline (); D: According to the given month, the corresponding season of the output (6The IF statement and the switch statement are the respective scene A:ifFor A Boolean type of judgment against a range of judgements for several constants of the judgment B:SwitchJudging for a few constants2: Loop statement (master) (1) There are three kinds: for, while, Do... while (2) for Loop statement A: Format for(Initialize statement; Judge conditional statement; Control condition statement) {loop body statement; Execution process: A: Execute initialization statement B: Execute judgment condition statement If this is true, continue If this is false, the loop will end C: Execute loop body statement D: Execute control condition statement e: Go back to b b: precautions A: Judging the conditional statement whether simple or complex, the result is a Boolean type B: The loop body statement if it is a bar, you can omit the curly braces, but it is not recommended that C: There is no left curly brace, there are left curly braces there is no semicolon C: case A: output 10 times HelloWorld B: Output 1-10 of data c: output ten-1 Data d: Ask 1-10 and E: Ask for 1-100 and, ask 1-100 even and 1-100 Odd and F: 5 factorial g: Print daffodils in console h: Number of Daffodils I: Improved version of palindrome number a five-digit number Digit=Universal 10-bit=thousand digit+ 10 bit + thousand + million + bit =hundred J: Statistics 1-1000 How many x are the data that meet the following conditions at the same time%3==2x%5==3x%7==2 (3) while loop A: basic format while(Judgment condition statement) {loop body statement; } Extended format: initialization statement; while(Judgment condition statement) {loop body statement; Control condition statement; By looking at this format, we know that the while loop can be converted to the For loop equivalent. B:while the practice of using the for statement with while to improve the difference between c:for and while a: use the difference between the control condition variable for the For statement, not at the end of the loop after the It's used. While the while can continue to be used. B: The difference in understanding for a range of judgments while fitting the number of ambiguous examples: eating grapes D: case: A: The pearl Brown Question B: Xiao Fang's saving problem (to be done after break) (4) Do... while loop A: basic format Do{loop body statement; } while(judging conditional statements); Extended format: initialization statement; Do{loop body statement; Control condition statement; } while(judging conditional statements); By looking at the format, we can see that in fact, the format of the three loops can be unified. B: The difference of three cycles a: Dothe While loop performs at least one loop body b:for and while must first determine if the condition is true before deciding whether to execute the loop body (5Precautions for recycling (dead Loop) A: Be sure to pay attention to modify the control conditions, otherwise prone to die cycle. B: The simplest form of dead loop A: while(true){...} B: for(;;) {} 3: Controls The jump statement (1) Break: Interrupt meaning A: used in loop and switch statements, leaving this scenario meaningless. B: Function A: normal circumstances can only jump out of the single-layer cycle B: jump out of the multi-layer cycle, the need for a label sentence matching
eg
BK: for (int i=0;i<100;i++) {
for (int j=0;j<100;j++) {
Break BK;
}
}
You can jump out of multiple loops directly!
(2)Continue: Continue A: used in loops, leaving this scenario meaningless. B: Function A: Jump out of the single-layer cycle once, you can continue to the next C: Fill in the blanks for(intX=1; x<=10; X + +) { if(x%3 = = 0) { //The code is padded} System.out.println ("Basic Java class"); How to get the console output 2 times: How to make the console output 7 times: Java Basic class How to make console output 13 times: Java Basic class (3)return: Returns a: Used to end the method, and will continue to be explained and used later. B: Once a return has been encountered, the program will not continue to execute in the future.
Java Fundamentals-Process Control statement considerations