Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8677725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:32:14+00:00 2026-06-12T20:32:14+00:00

My assignment instructions are rolling 2 dice and getting the sum and then finding

  • 0

My assignment instructions are “rolling” 2 dice and getting the sum and then finding the probability that that sum came up based on how many times the user wants to roll the die. I must use a nested loop and I can’t use separate loops for each dice combination (which I haven’t done). I am not allowed to use arrays in this assignment.

Write a program to simulate tossing a pair of 11-sided dice and determine the percentage of times each possible combination of the dice is rolled.

  1. Create a new project called 5.05 Random Dice in the Mod05 Assignments folder.
  2. Create a class called DiceProbability in the newly created project folder.
  3. Ask the user to input how many times the dice will be rolled.
  4. Calculate the probability of each combination of dice. (You may want to start with more familiar six-sided dice.)
  5. Print the results neatly in two columns

I need help in finding out what I put into the second “for” loop. Sorry for the messy list of integers and if statements. The code is unfinished.

import java.util.Random;
import java.util.Scanner;
public class DiceProbability
{
public static void main(String[] args)
{
    Scanner in = new Scanner(System.in);
    Random randNum = new Random();

    int count2 = 0;
    int count3 = 0;
    int count4 = 0;
    int count5 = 0;
    int count6 = 0;
    int count7 = 0;
    int count8 = 0;
    int count9 = 0;
    int count10 = 0;
    int count11= 0;
    int count12= 0;
    int count13 = 0;
    int count14 = 0;
    int count15 = 0;
    int count16 = 0;
    int count17 = 0;
    int count18 = 0;
    int count19 = 0;
    int count20 = 0;
    int count21 = 0;
    int count22 = 0;
    int die1 = 0, die2 = 0;
    int rolls = 0;
    int actualDiceSum;
    double probabilityOfDice = 0.0;

    System.out.print("Number of Rolls: ");
    rolls = in.nextInt();

    for(int timesRolled = 0; timesRolled < rolls; timesRolled++)
        {
        die1 = randNum.nextInt(12);
        die2 = randNum.nextInt(12);
        actualDiceSum = die1 + die2;
        for()
        {
            if(actualDiceSum == 2){
            count2++;
            probabilityOfDice = count2 / rolls;
            }
            else if(actualDiceSum == 3){
            count3++;
            probabilityOfDice = count3 / rolls;
            }
            else if(actualDiceSum == 4){
            count4++;
            probabilityOfDice = count4 / rolls;
            }
            else if(actualDiceSum == 5){
            count5++;
            probabilityOfDice = count5 / rolls;
            }
            else if(actualDiceSum == 6){
            count6++;
            probabilityOfDice = count6 / rolls;
            }
            else if(actualDiceSum == 7){
            count7++;
            probabilityOfDice = count7 / rolls;
            }
            else if(actualDiceSum == 8){
            count8++;
            probabilityOfDice = count8 / rolls;
            }
            else if(actualDiceSum == 9){
            count9++;
            probabilityOfDice = count9 / rolls;
            }
            else if(actualDiceSum == 10){
            count10++;
            probabilityOfDice = count10 / rolls;
            }
            else if(actualDiceSum == 11){
            count11++;
            probabilityOfDice = count11 / rolls;
            }
            else if(actualDiceSum == 12){
            count12++;
            probabilityOfDice = count12 / rolls;
            }
            else if(actualDiceSum == 13){
            count13++;
            probabilityOfDice = count13 / rolls;
            }
            else if(actualDiceSum == 14){
            count14++;
            probabilityOfDice = count14 / rolls;
            }
            else if(actualDiceSum == 15){
            count15++;
            probabilityOfDice = count15 / rolls;
            }
            else if(actualDiceSum == 16){
            count16++;
            probabilityOfDice = count16 / rolls;
            }
            else if(actualDiceSum == 17){
            count17++;
            probabilityOfDice = count17 / rolls;
            }
            else if(actualDiceSum == 18){
            count18++;
            probabilityOfDice = count18 / rolls;
            }
            else if(actualDiceSum == 19){
            count19++;
            probabilityOfDice = count19 / rolls;
            }
            else if(actualDiceSum == 20){
            count20++;
            probabilityOfDice = count20 / rolls;
            }
            else if(actualDiceSum == 21){
            count21++;
            probabilityOfDice = count21 / rolls;
            }
            else if(actualDiceSum == 22){
            count22++;
            probabilityOfDice = count22 / rolls;
           }
        }
    }


    System.out.println("Sum of Dice \t\t Probability");
    System.out.println("2's\t\t" + probabilityOfDice + "%");
    System.out.println("3's\t\t" + probabilityOfDice + "%");
    System.out.println("4's\t\t" + probabilityOfDice + "%");
    System.out.println("5's\t\t" + probabilityOfDice + "%");
    System.out.println("6's\t\t" + probabilityOfDice + "%");
    System.out.println("7's\t\t" + probabilityOfDice + "%");
    System.out.println("8's\t\t" + probabilityOfDice + "%");
    System.out.println("9's\t\t" + probabilityOfDice + "%");
    System.out.println("10's\t\t" + probabilityOfDice + "%");
    System.out.println("11's\t\t" + probabilityOfDice + "%");
    System.out.println("12's\t\t" + probabilityOfDice + "%");
    System.out.println("13's\t\t" + probabilityOfDice + "%");
    System.out.println("14's\t\t" + probabilityOfDice + "%");
    System.out.println("15's\t\t" + probabilityOfDice + "%");
    System.out.println("16's\t\t" + probabilityOfDice + "%");
    System.out.println("17's\t\t" + probabilityOfDice + "%");
    System.out.println("18's\t\t" + probabilityOfDice + "%");
    System.out.println("19's\t\t" + probabilityOfDice + "%");
    System.out.println("20's\t\t" + probabilityOfDice + "%");
    System.out.println("21's\t\t" + probabilityOfDice + "%");
    System.out.println("22's\t\t" + probabilityOfDice + "%");
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:32:15+00:00Added an answer on June 12, 2026 at 8:32 pm

    Well according to me you don’t require 2nd for loop.
    Every time a dice is rolled you calculate the the sum and increase the count according to the sum.

    you would require to use separate variables for calculating the probability of each sum.

    For example

    Probability of count2 = (count2/number of rolls);
    Probability of count3 = (count2/number of rolls);
    

    Use separate variables for probability of counts

    try this code

    import java.util.Random;
    import java.util.Scanner;
    public class DiceProbability
    {
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        Random randNum = new Random();
    int count2 = 0;
    int count3 = 0;
    int count4 = 0;
    int count5 = 0;
    int count6 = 0;
    int count7 = 0;
    int count8 = 0;
    int count9 = 0;
    int count10 = 0;
    int count11= 0;
    int count12= 0;
    int count13 = 0;
    int count14 = 0;
    int count15 = 0;
    int count16 = 0;
    int count17 = 0;
    int count18 = 0;
    int count19 = 0;
    int count20 = 0;
    int count21 = 0;
    int count22 = 0;
    int die1 = 0, die2 = 0;
    int rolls = 0;
    int actualDiceSum;
    double probabilityOfDice = 0.0;
    
    System.out.print("Number of Rolls: ");
    rolls = in.nextInt();
    
    for(int timesRolled = 0; timesRolled < rolls; timesRolled++)
        {
        die1 = randNum.nextInt(12);
        die2 = randNum.nextInt(12);
        actualDiceSum = die1 + die2;
    
            if(actualDiceSum == 2){
            count2++;
    
            }
            else if(actualDiceSum == 3){
            count3++;
    
            }
            else if(actualDiceSum == 4){
            count4++;
    
            }
            else if(actualDiceSum == 5){
            count5++;
    
            }
            else if(actualDiceSum == 6){
            count6++;
    
            }
            else if(actualDiceSum == 7){
            count7++;
    
            }
            else if(actualDiceSum == 8){
            count8++;
    
            }
            else if(actualDiceSum == 9){
            count9++;
    
            }
            else if(actualDiceSum == 10){
            count10++;
    
            }
            else if(actualDiceSum == 11){
            count11++;
    
            }
            else if(actualDiceSum == 12){
            count12++;
    
            }
            else if(actualDiceSum == 13){
            count13++;
    
            }
            else if(actualDiceSum == 14){
            count14++;
    
            }
            else if(actualDiceSum == 15){
            count15++;
    
            }
            else if(actualDiceSum == 16){
            count16++;
    
            }
            else if(actualDiceSum == 17){
            count17++;
    
            }
            else if(actualDiceSum == 18){
            count18++;
    
            }
            else if(actualDiceSum == 19){
            count19++;
    
            }
            else if(actualDiceSum == 20){
            count20++;
    
            }
            else if(actualDiceSum == 21){
            count21++;
    
            }
            else if(actualDiceSum == 22){
            count22++;
    
           }
        }
    }
    
    
    System.out.println("Sum of Dice \t\t Probability");
    System.out.println("2's\t\t" + count2/rolls + "%");
    System.out.println("3's\t\t" + count3/rolls + "%");
    System.out.println("4's\t\t" + count4/rolls + "%");
    System.out.println("5's\t\t" + count5/rolls + "%");
    //and so on...
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The assignment instructions are so: Write a method named evenSum that prompts the user
My assignment is to write an overloaded version of iquote() , a method that
My assignment is to create a simple graph that has both Nodes and Edges.
My assignment requires that I have an ER diagram that shows the dependencies between
I was given the assignment to create a program that performs basic set operations.
I have an assignment that I'm supposed to implement the MIPS processor in C++
I have this loop that parses machine code and emulates the instructions as if
I've been working on Java homework. Here are my instructions: Interface Programming Assignment Create
I have an assembly code which is 100 times these two instructions : movl
My assignment says to throw a try and catch for this: If the user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.