Java Learning notes: Java Process Control

Source: Internet
Author: User

First, Introduction

Java Process Control includes sequential control, conditional control, and loop control .

Sequential control is the execution of each statement from beginning to end. Conditional control, which executes the statement based on the condition selection, for example, if the condition is true, the action A is executed, or if the condition is true, the action A is executed, and the action B is executed instead. Cyclic control, also known as loop control, performs the operation of the loop body according to the cyclic initial conditions and termination requirements.

Sequential structures can only be executed sequentially, not judged and chosen, so branching structures are required.

There are two types of branching structures in Java:

    • If statement
    • Switch statement

There are three main loop structures in Java:

    • While loop
    • Do...while Cycle
    • For loop
Second, notes
 PackageCom.hgd.study2;ImportJava.util.Scanner;/*** Java Process Control: sequential structure of the mechanism of the structure of the loop * *@authorHutiger sequential structure: Through the debug mode, you can see the Java program's run-time sequential structure of the * branching structure: if statement **/ Public classProcesscontrol { Public Static voidMain (string[] args) {//Ifstudy (); //Switchcasestudy (); //whilestudy ();    }    /** If statement*/    Private Static voidIfstudy () {/** World represented by conditions (true| | FALSE) to determine whether to enter the statement block if (conditional expression) {statement Block} to continue executing the following statement*/        inti = 100; if(I > 60) {System.out.println (i); } System.out.println ("Statements that need to be executed later"); /** If Else statement*/        //system.in is the standard input, you can get the value entered from the keyboard//process the acquired data through scanner (the tool that the JDK provides to us)System.out.println ("Please enter your score!")); Scanner SC=NewScanner (system.in); intj = Sc.nextint ();//assign the number of user input to JSYSTEM.OUT.PRINTLN ("The console Gets the value is:" +j); if(J > 60) {System.out.println (By); } Else{System.out.println ("Didn't pass."); } System.out.println ("What needs to be done after if else executes"); /** If else if else if ... else*/        //scenario: Divide a 5 (score) into: 5 points rating a 4==b 3==c others are DScanner SCA =NewScanner (system.in); intScore =Sca.nextint (); if(Score >= 0 && score <= 5) {            if(Score = = 5) {System.out.println (A); } Else if(Score = = 4) {System.out.println (B); } Else if(Score = = 3) {System.out.println (C); } Else{System.out.println (D); }        } Else{System.out.println ("Input not valid"); }        /** Exercise: Percentile system 90-100 excellent 75-89 good 60-74 qualified other unqualified*/Scanner Scan=NewScanner (system.in); intScore1 =Scan.nextint (); if(score1 >= 0 && score1 <= 100) {            if(Score1 >= && score1 <= 100) {System.out.println (Excellent); } Else if(Score1 >= 75) {System.out.println (Good); } Else if(Score1 >= 60) {System.out.println (Qualified); } Else{System.out.println ("Non-conformities"); }        } Else{System.out.println ("Input not valid"); }    }    /** Switch case*/    Private Static voidSwitchcasestudy () {/** Branching statement: Switch case key: the expression to be compared value: The values to compare with the expression * Execution flow: If the result of the comparison between key and value is true, the case part of the code will be executed There are several similar to else if parts * differences between key and value can only be = = = The default part is not satisfied with any of the above to execute the code, similar to else * * Switch after the expression in parentheses The value must be a constant expression that conforms to the Byte,char,short,int type jdk1.7 can use String * instead of floating-point or long type * switch (key) {case Val Ue:break; Default:break; }         */        //scenario: Divide a 5 (score) into: 5 points rating a 4==b 3==c others are DScanner sc =NewScanner (system.in); intScore =Sc.nextint (); Switch(score) { Case5: System.out.println (A);  Break;//standard notation break cannot jump out of the current statement block, if no break will go directly to the next case statement         Case4: System.out.println (B);  Break;  Case3: System.out.println (C);  Break; default: System.out.println (D);  Break; }    }    /** While loop and do While*/    Private Static voidWhilestudy () {/** Execution Process: When the conditional expression is true, enter the code block, execute the code that needs to be executed when the conditional expression is false, execute the following statement * * while (conditional expression) {The part of the code that needs to be executed} Statement of the Polygon*/        /** Scene: Input 1-100 integer analysis: Give the output value a variable i, when I is between 1-100 output*/        inti = 1;//starting point of the cycle         while(I <= 100) {System.out.println (i); //give the step of the loopi++; } System.out.println ("End of print"); /** Do While * * do{*}while (conditional expression)*/                intA=1;  Do{//the contents of a statement block are executed one time, regardless of whether the condition satisfiesSystem.out.println (a); A++; }         while(a<=0); }    /** For Loop*/    Private Static voidForstudy () {/** Scene: print 1-100 int i=1 is the starting point of the loop i++ loop compensation i<=100 The condition of the loop*/         for(inti = 1; I <= 100; i++) {System.out.println (i); } System.out.println ("End of print"); }}

Java Learning notes: Java Process Control

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.