If statement
Dice Game (Dicegame):
public class Dicegame {
public static void Main (string[] args) {
Double s = math.random ();
int d = 1+ (int) (6*s);
if (d==6) {
System.out.println ("Your points are:" +d+ "Your luck is so good!" ");
}else if (d>=4) {
System.out.println ("Your points are:" +d+ "good luck." But it's already awesome! ");
}else if (d>=2) {
System.out.println ("Your points are:" +d+ "luck is a bit poor ha!") We need to work harder! ");
}else{
System.out.println ("Your points are:" +d+ "OK, you are very back, give you a chance!" ");
}
}
}
Switch statement
It is important to note that the switch statement has a case-penetrating phenomenon. So in normal use to pay attention to this, but there are some special circumstances we can also use this so-called case penetration phenomenon to achieve our goal.
eg://Letter Vowel Consonant judging procedure
public class test{
public static void Main (string[] args) {
Char letter = ' a ';
int randomnumber = (int) (26* (Math.random ()));
Char letter2 = (char) (letter + Randomnumber);
System.out.println (LETTER2);
Switch (letter2) {
Case ' a ':
Case ' E ':
Case ' I ':
Case ' O ':
Case ' U ':
System.out.println ("vowel Letter");
Break
Case ' Y ':
Case ' W ':
SYSTEM.OUT.PRINTLN ("semivowels letter");
Break
Default
SYSTEM.OUT.PRINTLN ("consonant letters");
break;
}
}
}
Java Learning notes-select structure