gpt4 book ai didi

java - 又遇到玩游戏的麻烦了

转载 作者:行者123 更新时间:2023-12-01 11:41:35 25 4
gpt4 key购买 nike

所以这是我的代码......我想找到一种方法如何再次玩......使用 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);
}
}

最佳答案

您可以在代码中添加周围的循环代码,在其中询问“再次播放”。像这样:

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
}

关于java - 又遇到玩游戏的麻烦了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29480497/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com