所以这是我的代码....我想找到一种方法再次玩...使用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);
}
}
答案 0 :(得分:1)
您可以在代码中添加一个周围的循环代码,您可以在其中询问“再次播放”。像这样:
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
}