Javase Review Diary: Conditional judgment statement

Source: Internet
Author: User
Tags case statement

/*                              Conditional Control statement: if () {}else{} syntax: First structure: There is no execution if (Boolean expression) {//First                Bit true, the execution of the inside of the statement, for false will not execute the 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 be a branch statement execution, because they all have an else statement.  The following example:*//*Public class javase{public static void Main (string[] args) {Boolean a = true;             if (a) {///If A is true, the following statement is output;         SYSTEM.OUT.PRINTLN ("Login Successful");             }else{//If A is false, the following statement is output;         SYSTEM.OUT.PRINTLN ("Login Failed"); }     } } *///there is a slightly more complicated case://the division of an Age (1~100岁) is defined as follows://[1-5] Toddlers//[6-18] Juvenile//[19-35] Youth//[36-55] Middle-aged//[56-100] old age////now a 54-year-old person, asked to write a code to determine the age of the person, and output the results;/*Public class javase{public static void Main (string[] args) {int = 54;//declaration variable, one person's age is 54 years old if (age&        Gt;=1 && age<=5) {System.out.println ("This person is a child");        }else if (age<=18) {System.out.println ("This person is a teenager");        }else if (age<=35) {System.out.println ("This person is a youth");        }else if (age<=55) {System.out.println ("This person is middle-aged");        }else if (age<=100) {System.out.println ("This person is old age"); }            }}*//** Conditional CONTROL Statement while * * * switch (int type) {//inside can only be Int/byte/short/char type, because can be self- //javase7, can be a string type * case INT type: * Execute the statement, and cannot be a long integer type, double type, Boolean type, etc. * * EXECUTE statement; * BREAK; * Case INT Type: * EXECUTE statement; * EXECUTE statement; * BREAK; * Case INT Type: * EXECUTE statement; * EXECUTE statement; * BREAK; * Case INT Type: * EXECUTE statement; * EXECUTE statement;      * BREAK; Can not * Default: * EXECUTE statement; Can not have a *} * break statement If there is no case statement penetrating phenomenon **/ Public classjavase{ Public Static voidmain (String [] args) {inti = (int)'in';//Forcing type conversionsSystem. out. println (i); CharC_0 = (Char) the; System. out. println (C_0); //Character Type        Charc ='B'; //char c = ' F ';        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'://Merge, if ABC has output the following ' excellent ', then stop here (break), otherwise ready to run down;System. out. println ("Excellent");  Break;  Case 'D': System. out. println ("General");  Break; default: System. out. println ("General"); }    }}

Javase Review Diary: Conditional judgment statement

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.