Home > Back-end >  9, JAVA conditional statements of the if... The else () with the switch... case...
9, JAVA conditional statements of the if... The else () with the switch... case...

Time:09-20

Package Study;

Public class test01 {

Public void test01 () {
//multiple if the judgment of the order: strict priority judging
the condition of//wrong judgment written
Int scor=88;
If (scor & gt;=60) {
System. The out. Println (" pass ");
} else if (scor & gt; {
=80)System. The out. Println (" good ");
} else {
System. The out. Println (" good ");
}
//judging correctly spelled
If (scor & gt; {
=90)System. The out. Println (" good ");
} else if (scor & gt; {
=80)System. The out. Println (" good ");
} else {
System. The out. Println (" pass ");
}
}
Public void test02 () {
//the same transaction, with multiple if
A double old=20;
String name="zs";
If (name. Equals (" zs ")) {
System. The out. Println (" zs ");
} the if (the name equals (" ls ")) {
System. The out. Println (" ls ");
}
//determine different transaction, with nested if
If (name. Equals (" zs ")) {
System. The out. Println (" name right ");
If (20) old=={
System. The out. Println (" youth ");
}
}
}
Public void test03 () {
//the use of the switch
Int rank=2;
The switch (rank) {
Case 1:
System. The out. Println (" rank=1 ");
break;
Case 2:
System. The out. Println (" rank=2 ");
break;
Default://equivalent to the if... The else... Statement of the else
System. Out.println (" rank=?" );
}
}
Public static void main (String [] args) {
Test01 test=new test01 ();
Test. Test01 ();
Test. Test02 ();
Test. Test03 ();
}

}