Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that allows the user to enter an integer n, and then generates n

ID: 3832325 • Letter: W

Question

Write a program that allows the user to enter an integer n, and then generates n random numbers between 1 and 100. The program calculates and prints the sum, average, and all the number above the average. Draw the flowchart for the program on the back this paper. Open Textpad and save the source file on the desktop using the file name as lastname final Write your name on the first line of the source file, and short comment for each task in the program. Leave the TextPad open and this paper on the keyword when you finish the exam.

Explanation / Answer

import java.util.Scanner;

public class RandomNumber {
public static void main(String args[]){
int num_count;//Value as input from user
int randNum[];//integer array to store the numbers
int num,sum=0;//to store numbers generated randomly and their sum
float num_avg=0.0f;// calculate average of all numbers
Scanner input=new Scanner(System.in);//taking input from user
System.out.print("Enter the number count= ");
num_count=input.nextInt();
randNum=new int[num_count];
for(int i=0;i<num_count;i++){
num=(int) (Math.random()*100);//generating random numbers between 1-100
randNum[i]=num;
sum=sum+num;// sum of all generated numbers
}
System.out.println("Randomly generated numbers are ****************");
for(int i=0;i<num_count;i++){
System.out.print(" "+randNum[i]);
}
num_avg=(float)sum/num_count;//average of all generated numbers
System.out.println(" Sum of generated numbers is= "+sum);
System.out.print("Average of generated numbers is = ");
System.out.printf("%.2f",num_avg);// formating average to 2 decimal place
System.out.println(" Numbers greater than the average of generated numbers is/are ********************");
for(int i=0;i<num_count;i++){
if(randNum[i]>=num_avg){//finding numbers greater than average
System.out.print(" "+randNum[i]);
}
}
System.out.println();
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote