Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a program using the Random class and While loops in Java. The program should generate a random number from 50 through 100. The loop

Create a program using the Random class and While loops in Java.

The program should generate a random number from 50 through 100. The loop should add the five random numbers generated. On each iteration of the loop the program should print out the number generated, how many numbers have been generated thus far, and the sum so far. On the last iteration, the printout should say the The final total is....

Teach comment the last time I did it:

*Your comments are way too long and should be written on multiple lines. *You did not follow the directions given at all. *You were supposed to print out the random number and the partial sum each iteration. Ie: The Random number for the number 4 generated is: 52 The partial sum is: 228 *You were supposed to print out on the last iteration the the final sum is and the last random number generated. ie: The Last random number is: 57 The final sum is: 285 *You have variables declared and initialized that are never used, and not needed *You used the wildcard import, which was not allowed Totally incorrect.

\_()_/

My ans:

//Generate a random number from 50 through 100, Add 5 random numbers generated. Then tells the user the number generated, how many nubmers have been generated thus far, and the sume so far. On the last iteration, the program should tell the user the final total is. //Jan 21, 2020

import java.util.*;

public class RandSum { public static void main(String[]args) { int sum=0, count=50, num; Random randNum=new Random(); int i=0; while(i<5) { num=randNum.nextInt(51)+count; System.out.println(num); sum+=num; i++; } System.out.println("The sum is "+sum); } }

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_2

Step: 3

blur-text-image_3

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

Database Design Application And Administration

Authors: Michael Mannino, Michael V. Mannino

2nd Edition

0072880678, 9780072880670

More Books

Students also viewed these Databases questions

Question

Factors Affecting Conflict

Answered: 1 week ago

Question

Describe the factors that lead to productive conflict

Answered: 1 week ago

Question

Understanding Conflict Conflict Triggers

Answered: 1 week ago