Switch of the Java conditional statement
Using a switch statement is more concise when you need to make an equivalent judgment on an option. For example: According to the rank of the exam, give the top 4 different prizes. First prize notebook one, second prize IPAD 21, Third prize mobile power one; the last one to reward u disk.
Syntax: 650) this.width=650; "src=" http://img.mukewang.com/5364f4c800010b1f01620289.jpg "/>
Execution procedure: When the value of the expression after switch is the same as the value after the case statement, it starts down from that position until the break statement is encountered or the switch statement block ends, and the code of the default block is executed if there is no matching case statement.
such as: 650) this.width=650; "src=" http://img.mukewang.com/5364f5e300010b6004790310.jpg "/>
Have to say a few little secrets:
1, switch the value of the expression after the parentheses must be integer or character type
2. The value after the case can be a constant value , such as 1, 2, or a constant expression , such as a. T, but not a variable or an expression with a variable, such as a * 2
3, case matching, execute the program code in the matching block, if not met break will continue to execute the contents of the next block of case until the break statement or switch statement block end such as 650) this.width=650; "src = "Http://img.mukewang.com/5364f6440001425d04810245.jpg"/>, running result: 650) this.width=650; "src="/HTTP/ Img.mukewang.com/5364f74800013d9101330090.jpg "/>
4. You can combine case statements with the same functionality, such as 650) this.width=650; "src=" http://img.mukewang.com/5364f6950001a57604280064.jpg "/>
5, the default block can appear in any position , you can also omit
Code:
public class Helloworld {
public static void Main (string[] args) {
Char today= ' Day ';
Switch (today) {
Case ' one ':
Case ' three ':
Case ' V ':
System.out.println ("Eat steamed buns");
Break
Case ' II ':
Case ' four ':
Case ' VI ':
System.out.println ("eat fritters");
Break
Default
System.out.println ("Eat Chairman's Package");
}
}
}
Running result: Eat Chairman's Package
This article is from "Ghost" blog, please make sure to keep this source http://caizi.blog.51cto.com/5234706/1547730
Java Basic---Switch for Java conditional statements (21)