Java Basic Course Learning notes (4)

Source: Internet
Author: User

1:switch Statement (master)(1) Format: switch (expression) {case value 1: statement body 1;   Break    Case Value 2: statement body 2;   Break    ... default: statement body n+1;  Break Format Explanation: Switch: Description This is a switch statement.expression: can be Byte,short,int,charJDK5 can be enumerated laterJDK7 can be a string laterCase: The value that follows is the value to compare to the expression break: Indicates that the program is interrupted here, jump out of the switch statement default: If all the cases do not match, execute here, equivalent to the else in the IF statement(2) face testCan a switch statement be an expression of byte?    Yes, can it be a long? Can it be a string?  No, JDK7 can (3) execute the Flow: A: First, the value of the expression B: and each case to match, if there is to execute the corresponding statement body, see Break to end. C: If there is no match, execute the default statement body n+1.(4) Precautions:A:case can only be a constant, cannot be a variable, and the value after multiple case cannot appear the same b:default could 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 you encounter a break 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(6) If statement and switch statement respective sceneA:If the judgment of the Boolean type against a range of judgments against a few constants b:switch the judgment of several constants2: Circular statement (master)(1) There are three kinds: for,while,do...while (2) For Loop statement   A: Format    for (initialization statement; Judgment condition statement; Control condition statement) {    loop Body Statement;   }       Execution Process:    A: Executing initialization statements     B: Executing a conditional statement       If this is true, continue       If this is false, the loop will end     C: Execute the Loop body statement     D: Execute the control condition statement     E: Back to b  B: Considerations   &NBSP;A: Judging conditional statements whether simple or complex, the result is a Boolean type   &NBSP;B: If the loop body statement is one, you can omit the curly brace, but it is not recommended   &NBSP;C: There is no left brace for the semicolon, There is no semicolon   C: Case    a: output 10 times helloworld   b: Output 1-10 data    c: Output 10-1 data    d: Ask for 1-10 and    e: 1-100 and, 1-100 even and 1-100 odd and    f: 5 factorial    g: print daffodils in console   &NBSP;H: Number of daffodils    i: Improved palindrome number     a five-digit     digit = million-bit     10-bit = thousands     digit + 10-bit + thousand + million-bit = hundred   &NBSP;J: Statistics 1-1000 How many     x%3==2    x%5==3    x%7==2 (3) while loops between data that meet the following criteria   A: Basic format   &NBSP;WHILE (judging conditional statement) {    loop body Statement;   }  &NBsp;    Extended Format:    Initialization statement;   while (judging conditional 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 Practice     Use while to improve the For statement practicethe difference between c:for and whileA: Use the difference on the control condition variable for the For statement, which cannot be used at the end of the loop.   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: Mt. Everest question B: Xiao Fang Save the problem (after break to do) (4) Do...while cycle A: basic format D   o {loop body statement;      }while (Judgment condition statement);   Extended format: initialization statement;    Do {loop body statement;   Control condition statement;      }while (Judgment condition statement); By looking at the format, we can see that in fact, the format of the three loops can be unified.B: The difference between three cyclesThe A:do...while loop executes at least once the loop body b:for and while must first determine if the condition is true before deciding whether to execute the loop body (5) Circular use Precautions (dead Loop) A: Be sure to pay attention to modify the control conditions, otherwise prone to the death cycle.    B: Simplest dead Loop format A:while (true) {...} B:for (;;) {}3: Control jump Statement (master)(1) Break: Interrupt meaning a: used in loops and switch statements, leaving this scenario meaningless.  B: Function A: Jump out of a single layer of the loop B: jump out of the multilayer loop, need the label statement of the Mate (2) Continue: Continue A: Used in the loop, leaving this scenario meaningless. B: Function A: Jump out of a single-layer cycle, you can continue to the next C: Fill in the blanks for (int x=1; x<=10; x + +) {if (x%3 = = 0) {//Complement code} SYSTEM.OUT.PRINTLN (   "Java Basic Course");  How to make the console output 2 times: Java Basic class How to make console output 7 times: Java Basic class How to let the console output 13 times: Java Basic Class (3) return: Returns A: Used to end the method, the following will continue to explain and use. B: Once a return has been encountered, the program will not continue to execute in the future.

Java Basic Course Learning notes (4)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.