Hi, I am required to: Create an array of 100 integers using a random generator. ( 1 for loop) Provide the sum and average of the array. (1 for loop) Find the smallest and largest number in the array. Determine its position in the array. (2 for loops) How many numbers are below the average, and how many numbers are above the average. (1 for loop) Print all data to the console, but do not print the array to the console. Unfortunately, the code that was sent to help me has come up with a bunch of errors. I really need help with identifiying which errors it is. Certain things look right but I'm sure where the errors are coming from.  Please include detailed descriptions and step by steps of how to correct this code for java.   //importing package for Random classimport java.util.Random; //main classpublic class Project_7 {//main method public static void main(String[] args) {//declaring an integer loop variable//declaring variable long type for storing the sum of all array elementslong sum=0;int i;//initiating random class Random randomNum = new Random();//creating an array with size of 100 elements int[] arrayNum = new int[100]; //using for loop to store the value in array created by random generatorfor(i=0;i<100; i++){//assigning random values to array arrayNum[i]=randomNum.nextInt(100);}//for loop to calculate the sum of all the array elementssum += arrayNum[i];}//printing out sum of array elements to console System.out.println("sum of array:"+sum); //calculating the average of array elements by dividing the sum of array elements by 100 i.e., total number of elements double avg = (double)sum/100;//calculating average of all array elementsSystem.out.println("average of array:" +avg);//assigning value of first index value to min int min = arrayNum[0];//initializing minindexvalue with 0int minindexvalue = 0;//using for loop to calculate the minimum array elements for(i=0;i<100;i++){//checking if the array element is smaller than min variableif(arrayNum[i]<min){//if the array element is smaller then assigning its value to the min variable min = arrayNum[i];//storing index valueminindexvalue = i;}}//displaying the minimum value and its index value to userSystem.out.println("Smallest number in the array is "+min+" and its position in the array is "+minindexvalue);//assigning value of first array element to the max int max = arr[0]; //initializing maxindexvalue with 0 int maxindexvalue = 0; //for loop for finding the maximum value of array element for(i=0;i<100;i++){ //checking if the value of array element is greater than max if(arr[i]>max) { //assigning the value of array element to max variable max = arr[i]; //storing index of max variable maxindexvalue = i; } } //dispalying the maximum value and its index value to user System.out.println("Largest number in the array is "+max+" and its position in the array is "+maxindexvalue); //varible for counting the number below the average int num_below_average =0; //varible for counting the number above the average int num_above_average =0; //for loop to find the number is below or above to the average for( i=0;i<100;i++) { //if the value is greater than average if((double)arr[i]<avg) { //incrementing the value of num_below_average num_below_average++; } //if the value is smaller than average else { //incrementing the value of num_above_average num_above_average++; } } //displayin the Numbers below the average: System.out.println("Numbers below the average: "+num_below_average); //displayin the Numbers above the average: System.out.println("Numbers above the average: "+num_above_average);   } } { } }

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter3: Assignment, Formatting, And Interactive Input
Section3.4: Program Input Using Cin
Problem 9E
icon
Related questions
Question

Hi, I am required to:

  • Create an array of 100 integers using a random generator. ( 1 for loop)
  • Provide the sum and average of the array. (1 for loop)
  • Find the smallest and largest number in the array. Determine its position in the array. (2 for loops)
  • How many numbers are below the average, and how many numbers are above the average. (1 for loop)
  • Print all data to the console, but do not print the array to the console.

Unfortunately, the code that was sent to help me has come up with a bunch of errors. I really need help with identifiying which errors it is. Certain things look right but I'm sure where the errors are coming from. 

Please include detailed descriptions and step by steps of how to correct this code for java.

 

//importing package for Random class
import java.util.Random;

//main class
public class Project_7
{
//main method
public static void main(String[] args)
{
//declaring an integer loop variable


//declaring variable long type for storing the sum of all array elements
long sum=0;
int i;
//initiating random class
Random randomNum = new Random();

//creating an array with size of 100 elements
int[] arrayNum = new int[100];

//using for loop to store the value in array created by random generator

for(i=0;i<100; i++)
{
//assigning random values to array
arrayNum[i]=randomNum.nextInt(100);
}
//for loop to calculate the sum of all the array elements
sum += arrayNum[i];
}

//printing out sum of array elements to console
System.out.println("sum of array:"+sum);


//calculating the average of array elements by dividing the sum of array elements by 100 i.e., total number of elements
double avg = (double)sum/100;

//calculating average of all array elements
System.out.println("average of array:" +avg);

//assigning value of first index value to min
int min = arrayNum[0];

//initializing minindexvalue with 0
int minindexvalue = 0;

//using for loop to calculate the minimum array elements
for(i=0;i<100;i++)
{
//checking if the array element is smaller than min variable
if(arrayNum[i]<min)
{
//if the array element is smaller then assigning its value to the min variable
min = arrayNum[i];

//storing index value
minindexvalue = i;
}
}

//displaying the minimum value and its index value to user
System.out.println("Smallest number in the array is "+min+" and its position in the array is "+minindexvalue);

//assigning value of first array element to the max

int max = arr[0];

//initializing maxindexvalue with 0

int maxindexvalue = 0;

//for loop for finding the maximum value of array element

for(i=0;i<100;i++){

//checking if the value of array element is greater than max

if(arr[i]>max)

{

//assigning the value of array element to max variable

max = arr[i];

//storing index of max variable

maxindexvalue = i;

}

}

//dispalying the maximum value and its index value to user

System.out.println("Largest number in the array is "+max+" and its position in the array is "+maxindexvalue);

//varible for counting the number below the average

int num_below_average =0;

//varible for counting the number above the average

int num_above_average =0;

//for loop to find the number is below or above to the average

for( i=0;i<100;i++)

{

//if the value is greater than average

if((double)arr[i]<avg)

{

//incrementing the value of num_below_average

num_below_average++;

}

//if the value is smaller than average

else

{

//incrementing the value of num_above_average

num_above_average++;

}

}

//displayin the Numbers below the average:

System.out.println("Numbers below the average: "+num_below_average);

//displayin the Numbers above the average:

System.out.println("Numbers above the average: "+num_above_average);

 

}

}




{

}

}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr