
Hello fellow programmers, I'm new to this site and will appreciate a little assistance with my programming excersises. There are no solutions to refer to and everything in my program makes sense to me and should technically work. However my software doesn't agree with me haha. Here is the instructions: "The DiceRolls application is not written generically. The application has "hard-coded" data, including the maximum random number in the nextInt() method and the initial and final values for i in the show counts for loop. Modify the DiceRolls application to prompt the user for the number of sides on each die, the num¬ber of dice to be rolled, and the number of rolls to make. For example, a ten-sided die will show a number between a 1 and a 10 on a roll. Rolling three ten-sided dice has the possible outcomes of 3 through 30. "
and this is what I wrote so far: import java.util.*; import java.lang.*;
public class DiceRolls { public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int numRolls;
int numDice;
int numSides;
int outcome;
System.out.println("How many Dice?");
numDice = input.nextInt();
System.out.println("How many Sides?");
numSides = input.nextInt();
/* prompt user for number of rolls */
System.out.print("And how many rolls? ");
numRolls = input.nextInt();
int[]outcomes = new int[numDice*numRolls];
/* roll dice and add to outcomes */
for (int roll = 0; roll < numRolls; roll++)
{
outcome =numDice*((int)(numSides * Math.random() + 1));
outcomes[outcome] += 1;
}
/* show counts of outcomes */
for (int i = numDice; i <= numDice*numRolls; i++)
{
System.out.println(i + ": " + outcomes [i] ) ;
}
}
}
thanks so much!
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.