alright, i have been working on this code for two days. it is an assignment for my ap comp science class. i have tried several experiments that have all not worked. im supposed to make a proram that simulates an 11 sided dice being rolled, and it has to use nested loops. the user has to input a number of rolls and the program is supposed to continue that many times. also i have to display the probability of each side of the die being rolled. if anyone has any help it is GREATLY appreciated. this is the way i went about doing it:
/**
*
*
* Nathan Gibson
*
*/
import java.util.Scanner;
import java.util.Random;
public class DiceProbability
{
public static void main(String [] args)
{
Scanner in;
in = new Scanner(System.in);
int counterTrials = 1;
int counter1 = 1;
int counter2 = 1;
int counter3 = 1;
int counter4 = 1;
int counter5 = 1;
int counter6 = 1;
int counter7 = 1;
int counter8 = 1;
int counter9 = 1;
int counter10 = 1;
int counter11 = 1;
System.out.println("Number of Rolls: ");
int numberOfRolls = in.nextInt();
int randomNumber = ((int)(0+ Math.random()* 11));
for(int side1 = 0; counterTrials <= numberOfRolls; numberOfRolls++)
{
randomNumber = ((int)(0+ Math.random()* 11));
if (randomNumber == 1)
{
counter1++;
counterTrials++;
}
}
for(int side2 = 0; counterTrials <= numberOfRolls; numberOfRolls++)
{
randomNumber = ((int)(0+ Math.random()* 11));
if (randomNumber == 2)
{
counter2++;
counterTrials++;
}
}
for(int side3 = 0; counterTrials <= numberOfRolls; numberOfRolls++)
{
randomNumber = ((int)(0+ Math.random()* 11));
if (randomNumber == 3)
{
counter3++;
counterTrials++;
}
}
for(int side4= 0; counterTrials <= numberOfRolls; numberOfRolls++)
{
randomNumber = ((int)(0+ Math.random()* 11));
if (randomNumber == 4)
{
counter4++;
counterTrials++;
}
}
for(int side5 = 0; counterTrials <= numberOfRolls; numberOfRolls++)
{
randomNumber = ((int)(0+ Math.random()* 11));
if (randomNumber == 5)
{
counter5++;
counterTrials++;
}
}
for(int side6 = 0; counterTrials <= numberOfRolls; numberOfRolls++)
{
randomNumber = ((int)(0+ Math.random()* 11));
if (randomNumber == 6)
{
counter6++;
counterTrials++;
}
}
for(int side7 = 0; counterTrials <= numberOfRolls; numberOfRolls++)
{
randomNumber = ((int)(0+ Math.random()* 11));
if (randomNumber == 7)
{
counter7++;
counterTrials++;
}
}
for(int side8= 0; counterTrials <= numberOfRolls; numberOfRolls++)
{
randomNumber = ((int)(0+ Math.random()* 11));
if (randomNumber == 8)
{
counter8++;
counterTrials++;
}
}
for(int side9 = 0; counterTrials <= numberOfRolls; numberOfRolls++)
{
randomNumber = ((int)(0+ Math.random()* 11));
if (randomNumber == 9)
{
counter9++;
counterTrials++;
}
}
for(int side10 = 0; counterTrials <= numberOfRolls; numberOfRolls++)
{
randomNumber = ((int)(0+ Math.random()* 11));
if (randomNumber == 10)
{
counter10++;
counterTrials++;
}
}
for(int side11= 0; counterTrials <= numberOfRolls; numberOfRolls++)
{
randomNumber = ((int)(0+ Math.random()* 11));
if (randomNumber == 11)
{
counter11++;
counterTrials++;
}
}
System.out.print("Sum Of Dice Probability");
System.out.print("\n1s " + " " + (double) (counter1/numberOfRolls * 100) + "%");
System.out.print("\n2s " + " " + (double) (counter2/numberOfRolls * 100) + "%");
System.out.print("\n3s " + " " + (double) (counter3/numberOfRolls * 100) + "%");
System.out.print("\n4s " + " " + (double) (counter4/numberOfRolls * 100) + "%");
System.out.print("\n5s " + " " + (double) (counter5/numberOfRolls * 100) + "%");
System.out.print("\n6s " + " " + (double) (counter6/numberOfRolls * 100) + "%");
System.out.print("\n7s " + " " + (double) (counter7/numberOfRolls * 100) + "%");
System.out.print("\n8s " + " " + (double) (counter8/numberOfRolls * 100) + "%");
System.out.print("\n9s " + " " + (double) (counter9/numberOfRolls * 100) + "%");
System.out.print("\n10s " + " " + (double) (counter10/numberOfRolls * 100) + "%");
System.out.print("\n11s " + " " + (double) (counter11/numberOfRolls * 100) + "%");
}
}
my problem was that i couldnt get the counters to work right therefore my probabilitys were wrong, so i changed that, but now when i run i am prompted to enter a number and then nothing happens.