Java BASICS (4): java Basics

Source: Internet
Author: User

Java BASICS (4): java Basics

Here are some of the knowledge points and code I summarized in my previous class. Most of the notes I think are very good and classic, sincerely hope that these will help those who want to learn!

It is inconvenient to upload code by module. There are also many things, and they are also clear! If you need it, you can leave your email in the comments. I will certainly send it to you for free! Thank you for making progress on this platform !! Remember that programmers are selfless !!!

Also very welcome to my blog to watch blog address: http://www.cnblogs.com/duscl/

 

/* 1: switch statement (GRASP) (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 description: switch: This is a switch statement. Expression: It can be byte, short, int, char after JDK5, or after enumerative JDK7, it can be a string case: the following value is the value break to be compared with the expression: indicates that the program is interrupted here, and the switch statement default exists: if all the conditions do not match, execute this command, which is equivalent to the else (2) in the if statement) can the expression of the switch statement be byte? Can it be long? Can it be a String? Yes, no. JDK7 and later can (3) execute the process: A: Calculate the expression value B First: match with each case. If yes, execute the corresponding statement body, the break ends. C: If no match exists, execute the default statement body n + 1. (4) Note: A: Only constants can be followed by A case, not variables. Moreover, the values after multiple cases cannot be the same B: default. Can this be omitted? It can be omitted, but it is not recommended because it serves as a prompt for incorrect situations. In special cases, the value can be fixed in case. Can A, B, C, D C: break be omitted? It can be omitted, but the result may not be what we want. There will be a phenomenon: case penetration. In the end, we recommend that you do not omit D: Must default be at the end? No, it can be anywhere. However, we recommend that you complete the process at the end. E: the end condition of the switch statement. a: It ends with A break. B: It ends with the execution. (5) Case: a: enter A number (1-7) on the keyboard ), the day of the week. B: Single-choice question C: Question about inputting a String on the keyboard String s = SC. nextLine (); D: outputs the corresponding seasonal (6) scenarios for the if statement and switch statement based on the given month.: if the boolean type is determined based on a range of several constants. B: switch determines several constants. 2. Cyclic statements (master) (1) there are three types:, while, do... while (2) for loop Statement A: Format: for (initialization statement; judgment Condition Statement; Control Condition Statement) {loop body statement;} Execution Process: a: Execute initialization statement B: execute the judgment condition statement. If it is true, continue. If it is false, the loop ends. c: Execute the loop body statement. d: Execute the Control Condition Statement. e: Return to B: note a: whether the condition statement is simple or complex, the result is boolean Type B: If the loop body statement is one, braces can be omitted, but c: there is no left braces if there is a semicolon. There is no semicolon in the left braces C: Case a: Output 10 times HelloWorld B: Output 1-10 Data c: Output 10-1 Data d: Evaluate 1-10 and e: Calculate the sum of 1, calculate the even number of 1-and the odd number of 1-and f: Calculate the factorial g of 5: print the number of daffodils on the console h: count the number of daffodils I: in the simplified version, the number of input files is a five-digit single-digit ten-digit single: count the number of x % 3 = 2 x % 5 = 3 x % 7 = 2 (3) while loop A that meets the following conditions: basic Format: while (Judgment Condition Statement) {loop body statement;} extended format: initialization statement; while (Judgment Condition Statement) {loop body statement; Control Condition Statement ;} by viewing this format, we know that the while loop can be equivalent to the for loop. B: The while exercise improves the difference between C: for and while with the for statement. a: The control condition variable of the for statement, it cannot be used after the loop ends. While can continue to use. B: understanding the difference. for example, the number of while fit times is not clear. for example: Grape eating D: Case: a: Mount Everest Problem B: xiao Fang saves money (break can be done later) (4) do... while loop A: Basic Format: do {loop body statement;} while (Judgment Condition Statement); extended format: initialization statement; do {loop body statement; Control Condition Statement ;} while (Condition Statement); by viewing the format, we can see that the three loop formats can be unified. B: The difference between the three loops. a: do... when a while loop is executed at least once, body B: for and while must first judge whether the condition is true before deciding whether to execute the loop body (5) Precautions for loop usage (endless loop) a: Be sure to modify the control conditions. Otherwise, an endless loop may occur. B: The simplest format of an infinite loop: while (true ){...} b: for (;) {} 3: Control jump Statement (master) (1) break: interrupt meaning A: Used in loop and switch statements, leaving this application scenario is meaningless. B: Role a: jump out of A single-layer loop B: jump out of a multi-layer loop, need the combination of tag statements (2) continue: continue A: Used in a loop, leave this Application Scenario meaningless. B: Role a: jump out of a single-layer loop and continue the next C: Fill in the blank question for (int x = 1; x <= 10; x ++) {if (x % 3 = 0) {// complete the code} System. out. println ("Java basic class");} How to Make the console output twice: how to make the Java basic class output 7 times: how to make the Java basic class output 13 times on the console: java basic class (3) return: return A: Used to end the method, will continue to explain and use later. B: Once return is encountered, the program will not continue to execute later. *\

 

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.