Chapter III Selection Structure
If basic syntax:
if (condition) {//Expression
code block
}
eg
int a = 10;
if (a > 1) {
System.out.println ("content");
}
if () {
code block
}else{
code block
}
eg
If (score >= 90) {
System.out.println ("Reward Mp4 One");
}else{
System.out.println ("shoot");
}
Syntax:
if (condition) {
//code block
}else if (condition) {
//code block
}eles if (condition) {
//code block
}..... {
//code block
}else{
//code block
}
eg:
if (score <=) {
System.out.println ("Pull out, shoot");
}else if (score <=) {
System.out.println ("Pull out, go to jail for 20 years");
}else if (score <=) {
System.out.println ("Find an Object");
}else{
System.out.println ("Let the object to throw!!!!" ");
}
Grammar:
if (condition) {
if (condition) {
.....
}else if (condition) {
.....
}else{
.......
}
}else{
.......
}
eg:
if (Miao <=) {
System.out.println ("Please enter gender (male, female, Transgender):");
//char gender = Input.next (). charAt (0);
String gender = Input.next ();
if (gender.equals ("male")) {
System.out.println ("Enter the men's finals");
}else if (gender.equals ("female")) {
System.out.println ("Enter the women's finals");
}else if (gender.equals ("transsexual")) {
System.out.println ("into the transsexual Finals");
}else{
System.out.println ("You are not Human");
}
}else{
System.out.println ("Obsolete!!! ");
}
Java Chapter III Selection structure