所以这是我的代码...我想找到一种方法来再次玩...使用while循环或其他方法...有人能帮我吗?
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("enter minimum of Yahtzee dice 2-9: ");
int min = input.nextInt();
System.out.print("enter maximum of Yahtzee dice 3-10: ");
int max = input.nextInt();
System.out.println("Dice Rolls\tYahtzee's Percentage Odds\t");
for (int i = min; i <= max; i++) {
int count = 0;
for (int j = 0; j <= 5000000; j++) {
Random generator = new Random();
YahtzeeDice d = new YahtzeeDice(generator, i);
if (d.IsAYahtzee()) {
count++;
}
}
System.out.printf("%d ", i);
System.out.printf("%d\t", 5000000);
System.out.printf("%d\t ", count);
System.out.printf("%f ", (double) count / 5000000);
double per = count / (double) 5000000;
int odds = (int) (1 / per);
System.out.printf("1 in %d\n", odds);
}
}发布于 2015-04-07 06:24:05
你可以在你的代码中添加一个环绕的循环代码,在这里你会问“再玩一次”。如下所示:
do{
//your code
System.out.print("Gib was ein: ");
String answer = br.readLine();
}while(answer.equal("yes"))你也可以把你的代码放在一个函数中。
do{
mcFunction
System.out.print("Gib was ein: ");
String answer = br.readLine();
}while(answer.equal("yes"))
public void myFunction(){
//your code
}https://stackoverflow.com/questions/29480497
复制相似问题