Java Basics (2)

Source: Internet
Author: User

1. Program flow control: Sequential structure, branch structure, loop structure, control loop structure.

Sequential structure: If there is no process control in the code, the program runs down one line at a line until the end of the program.

2. Judgment statement if statement

The format of the IF statement:

Way One:

if (expression) {     method body}

Way two:

if (expression) {     execute statement;      }else{    execute statement;}

Way three:

if (expression) {    executestatement;}elseif(execute statement) {      execute statement;}Else{EXECUTE statement;    } 

3. SELECT statement, switch statement

Format:

Switch (expression) {   case  expression:         execution statement;   break;     Case expression:         execute statement   ;break;     Case expression:         execute statement   ;break;    default :         execute statement;   break;  // can write can not write;}

Case and default are not in order, first to execute first cases, there is no matching time to execute the default, the end of the switch statement of two situations, one is break, if there is no break, then a line of execution, until the end, If a match is performed, the subsequent code will be executed.

Example:

classSwitch { Public Static voidMain (string[] args) {intA =7, B =5; Switch(A-b) { Case 3://the possible values of the expression;{System. out. println ("33!"); }             Break;  Case 4: {System. out. println ("44!"); }             Break; default://an option that does not execute executes the statement!System. out. println ("Other of"); }    }}

The values in switch can be bye, char, short, int four basic data types, and their wrapper classes and enumerations, string is an object, not a basic data type.

4. Loop structure: Used to deal with repetitive execution, according to the value of judging conditions, determine the number of execution of the program paragraph, and this program we become the loop body.

The loops are: While,for,do......while.

While: You don't need to know how many loops are in advance, just the time it takes to get the data done.

Do......while: It's the same as above, but he will do it first, in judgment.

For need to know the number of cycles;

Format:while(condition) {EXECUTE statement}

Format of the Do......while

 Do {  execute statement;}while (condition);

While: Can not be executed, do......while: at least once.

Java Basics (2)

Related Article

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.