savedbyone
2011-10-20 17:49:28 UTC
My assignment says:
"Store the sum resulting from each roll of two dice in an array, determine the number of times each 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, and 12 was rolled, and determine the number of the roll on which the last 7 and the number of the roll on which last 11 occurred.
The output should indicate the frequency of each possible sum resulting from a roll, and should indicate the rolls on which the last 7 and the last 11 occurred. Output should go to command line screen."
Could someone look at my code and help me fix this??
import java.util.Random;
public class diceroll {
public static void main(String[] args) {
Random randomNumbers = new Random();
int die1;
int die2;
int[] totals = new int[13];
for (int index = 0; index < totals.length; index++)
totals[index]=0;
for (int roll = 1; roll <= 1000; roll++){
die1 = 1 + randomNumbers.nextInt(6);
die2 = 1 + randomNumbers.nextInt(6);
totals[die1 + die2]++;
}
System.out.printf(" %12s%18s\n",
"Sum of Spots on Faces"," Frequency of Sum");
for (int k = 2; k < totals.length; k++){
System.out.printf(" %12d%22d\n", k, totals[k]);
}
System.out.println();
System.out.println("Seven last occured on roll");
System.out.println("Eleven last occured on roll");
}
}