Java Process Control

Source: Internet
Author: User

The xmind is still used to show the general content of Java Process Control:

----------------------------------------------------

Variable Example:

 Public classa02{ Public Static voidMain (string[] args) {intA =Ten;//int size memory space, and named A, assign a value ofSystem. out. println (a); A= -;//variable Value re-assignmentSystem. out. println (a);//variable cannot be duplicate in same domain        intb//variables must be declared before they can be used, that is, space must be divided firstb =Ten;//Unassigned variables cannot be accessedSystem. out. println (b); intC1,C2,C3 = -;//Multiple variables can be declared at the same time, variables and variables are separated directly by commasSystem. out. println (); }        Static voidd () {intA =1;//variable names can be the same in different domains        }    }
 Public classa03{int var= -;  Public Static voidA (string[] args) {int var= $; System. out. println (var ); }     Public Static voidMain (string[] args) { for(intj =0; j<5; ++j) {System. out. println (j); }         for(intb =0; b<Ten; ++b) {System. out. println (b); }    }}

--------------------------------------------------------

If examples and precautions:

 Public classa01{ Public Static voidMain (string[] args) {Boolean a=true;//is set to true here        if(a) {System. out. println ("Silly" ); }Else{System. out. println ("Idiot" ); }    }}    /*               First structure: There is no execution if (Boolean expression) {///First bit true, executes the inside statement, False does not execute Java statement;                The second structure: if (Boolean expression) {Java statement;                }else{Java statements;                The third structure: multiple conditional discriminant, with non-executable if (Boolean expression) {Java statement;                }else if (Boolean expression) {Java statement;                }else if (Boolean expression) {Java statement;                }else if (Boolean expression) {Java statement;                The fourth structure: Overwrite all cases if (Boolean expression) {Java statement;                }else if (Boolean expression) {Java statement;                }else if (Boolean expression) {Java statement;                }else if (Boolean expression) {Java statement;                }else{Java statements;    Note: The entire if statement ends if there is only one branch executing in the IF statement. The above structure 2, 4, can guarantee that there will beA branch statement executes because they all have an else statement. */

-------------------------------------------------------

Switch example confirms:

 Public classa01{ Public Static voidmain (String [] args) {inti = (int)'Country'; System. out. println (i); CharC_0 = (Char) $; System. out. println (C_0); //Character Type        Charc ='A'; Switch(c) { Case 'A': System. out. println ("Excellent");  Break;  Case 'B': System. out. println ("Excellent");  Break;  Case 'C': System. out. println ("General");  Break; default: System. out. println ("Poor"); }        //Case Merge:        Charc_02 ='D'; Switch(c_02) { Case 'A': Case 'B': Case'C': System. out. println ("Excellent");  Break;  Case 'D': System. out. println ("General");  Break; default: System. out. println ("General"); }    }}

-------------------------------------------------------------

For loop Example:

/** For loop: syntax: for (expression 1; expression 2; expression 3) {Java statement; } Three conditions for the loop: 1, initial value 2, final value 3, final step reached, condition. */ Public classa01{ Public Static voidMain (string[] args) {intA =8;  for(;a<Ten; a++) {System. out. println ("a="+a); }         for(intb=Ten;b>1; b--) {System. out. println ("b="+b); }            }}

----------------------------------------

While example:

/*about while loop syntax: while (Boolean expression) {//Result value is TRUE or false Java statement; The number of While loops is: 0-n times while is true loop for Count Loop*/ Public classwhiletest01{ Public Static voidMain (string[] args) {//dead Loop        /*while (true) {System.out.println ("Test"); }        */                /*int i = 0;            while (i<10) {i++; System.out.println (i); 1 ... 9}*/                        inti =0;  while(i<Ten) {System. out. println (i);//0 ... 9i++; }            }}

--------------------------------------------------

Dowhile syntax and examples:

/*Do ..                While..            Syntax: do{java statements;                }while (boolean-expression); The number of times the loop executes is: 1-n*/ Public classdowhiletest01{ Public Static voidMain (string[] args) {inti =0;  Do{                        //i++;System. out. println (i); I++; } while(i<Ten); }}

-----------------------------------------------------

Examples of break types:

/** Break ; the statement * 1. In the switch statement, end the branch statement; * 2. break; or it can be used in a loop, by default, to end a loop that is closest to him * break; end loop * Continue; skip this Cycle, continue the next loop (combined with conditional statements) * Return: End method Sickness returns a value*/ Public classbreak_01{ Public Static voidMain (string[] args) { for(intI=0; i<Ten; i++) {System. out. println (i); if(i==5){                 Break;//just to end the loop that's closest to him.}} System. out. println ("Hello world!!"); }}

Break End Loop
Continue Skip this cycle and continue the next loop (combined with conditional statements)
Return: End method and return a value

Java control process is probably the above points, I hope you have a lot of advice.

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.