?? choice.java
字號(hào):
//Chapter 3, Exercise 1
public class Choice {
public static void main(String args[]) {
// Use an integer to determine the choice:
int myChoice = 0;
// Select a random value for myChoice between 0 and 5:
myChoice = (int)(6.0*Math.random());
// The above line ensures each integer from 0 to 5 is equiprobable.
// Multiplying the value produced by random() by 6.0 results in a value
// from 0.0 to 5.99999
// Values from 0 to 0.99999 becomes 0, from 1.00 to 1.99999 becomes 1,
// and so on, with values from 5.0 to 5.99999 becoming 5.
// Print the appropriate Breakfast Choice depending on value myChoice:
switch(myChoice) {
case 0:
System.out.println("Breakfast choice is scrambled eggs");
break;
case 1:
System.out.println("Breakfast choice is waffles");
break;
case 2:
System.out.println("Breakfast choice is fruit");
break;
case 3:
System.out.println("Breakfast choice is cereal");
break;
case 4:
System.out.println("Breakfast choice is toast");
break;
case 5:
System.out.println("Breakfast choice is yogurt");
break;
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -