?? dice.java
字號:
import java.util.Random;
import java.io.IOException;
public class Dice
{
public static void main(String[] args)
{
System.out.println("You have six throws of a pair of dice.\n" +
"The objective is to get a double six. Here goes...\n");
Random diceValues = new Random(); // Random number generator
String[] theThrow = {"First ", "Second ", "Third ",
"Fourth ", "Fifth ", "Sixth "};
int die1 = 0; // First die value
int die2 = 0; // Second die value
for(int i = 0; i < 6; i++)
{
die1 = 1 + Math.abs(diceValues.nextInt())%6; // Number from 1 to 6
die2 = 1 + Math.abs(diceValues.nextInt())%6; // Number from 1 to 6
System.out.println(theThrow[i] + "throw: " + die1 + ", " + die2);
if(die1 + die2 == 12) // Is it double 6?
{
System.out.println(" You win!!"); // Yes !!!
return;
}
}
System.out.println("Sorry, you lost...");
return;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -