Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task #2 Using Other Types of Loops Change the while loop to a do-while loop. Compile and run. You should get the same results. Change

Task #2 Using Other Types of Loops

Change the while loop to a do-while loop. Compile and run. You should get the same results.

Change the do-while loop to a for loop. Compile and run. You should get the same results.

import java.util.Random; // Needed for the Random class 
/** This class simulates rolling a pair of dice 10,000 times and counts the number of times doubles of are rolled for each different pair of doubles. 

*/

public class DiceSimulation { 
 public static void main(String[] args) { 
 final int NUMBER = 10000; // Number of dice rolls 
 // A random number generator used in // simulating the rolling of dice Random generator = new Random(); 

int die1Value; // Value of the first die int die2Value; // Value of the second die int count = 0; // Total number of dice rolls int snakeEyes = 0; // Number of snake eyes rolls int twos = 0; // Number of double two rolls 
int threes = 0; // Number of double three rolls int fours = 0; // Number of double four rolls int fives = 0; // Number of double five rolls int sixes = 0; // Number of double six rolls 
// TASK #1 Enter your code for the algorithm here 

Copyright 2019 Pearson Education, Inc., Hoboken NJ

} }

// Display the results System.out.println ("You rolled snake eyes " + 
 snakeEyes + " out of " + 
 count + " rolls."); System.out.println ("You rolled double twos " + twos + " out of " + count + 
 " rolls."); System.out.println ("You rolled double threes " + 
 threes + " out of " + count + 
 " rolls."); System.out.println ("You rolled double fours " + 
 fours + " out of " + count + 
 " rolls."); System.out.println ("You rolled double fives " + 
 fives + " out of " + count + 
 " rolls."); System.out.println ("You rolled double sixes " + 
 sixes + " out of " + count + " rolls."); 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Office 365 For Beginners 2022 8 In 1

Authors: James Holler

1st Edition

B0B2WRC1RX, 979-8833565759

Students also viewed these Databases questions

Question

Describe new developments in the design of pay structures. page 475

Answered: 1 week ago