0
このプログラムをループする際に問題があります。私はプライベートメソッドのすべてが正しいと信じていますが、私はループを作成するための主要なメソッドを取得できません。コードは以下の通りであり、コメントにはコードの内容が記載されています。Javaでルーピング....?
ありがとうございました。
import java.util.Random;
/**
* This program rolls the dice three times and the profit is the sum of the face
* values that are obtained. Fives do not count and no roll after a five counts.
* The program will be run 1 million times and the results will be averaged
*
* @author --
*/
public class FatalFives {
public static void main(String[] args) {
final int TRIALS = 1000000;
int count = 0;
while (count < TRIALS) {
count++;
}
double avg = (double) profit/TRIALS;
System.out.println("Your average winnings are: $" + avg);
}
private static int FatalFive() {
Random rand = new Random();
int profit = 0;
int die1 = 1 + rand.nextInt(6);
int die2 = 1 + rand.nextInt(6);
int die3 = 1 + rand.nextInt(6);
if (die1 == 5) {
//System.out.println("You're unlucky, no profit");
profit = 0;
} else if (die1 != 5 && die2 == 5) {
//System.out.println("Congrats! You won $" + die1);
profit = (die1);
} else if (die3 == 5) {
//System.out.println("Congrats! You won $" + die1 + die2);
profit = (die1 + die2);
} else if (die1 != 5 && die2 != 5 && die3 != 5) {
//System.out.println("Congrats! You won $" + (die1 + die2 + die3));
profit = (die1 + die2 + die3);
}
return profit;
}
}