[英]Having trouble with play again
所以這是我的代碼。...我想找到一種方法來再次播放...使用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
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.