Hi I am coding with java. I am given the instructions: 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. I coded all of this from the last time I got help from you guys. The instructions are just to give an idea of what I had to do. I really need help in breaking up my coding. Apparently I need to add methods in it and I'm not sure which method and where would work. Please show me how to do this. Thanks! Here's my code: //Brianna Fisher COMP 1000 //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 variableint i; //declaring variable long type for storing the sum of all array elementslong sum=0;//initiating random class Random randNum = new Random();//creating an array with integer type and array 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++){//appointing random values to array arrayNum[i]=randNum.nextInt(100); }//for loop to calculate the sum of all the array elementsfor(i=0;i<100;i++){// storing 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 sum by 100 double avg = (double)sum/100;//calculating average of all arraysSystem.out.println("Average of array:" +avg);//assigning value of first index value to min int min = arrayNum[0];//intializing 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 its value can be assigned to the min variable min = arrayNum[i];//storing index valueminindexvalue = i;}}//displaying the minimum value and its index value to consoleSystem.out.println("Smallest number in array is "+ min +" and its position in array is "+ minindexvalue);//assigning value of first array element to the maxint max = arrayNum[0]; //initializing maxindexvalue with 0int maxindexvalue = 0; //for loop for finding the maximum value of array elementfor(i=0;i<100;i++){//checking if the value of array element is greater than maxif(arrayNum[i]>max){ //assigning the value of array element to max variablemax = arrayNum[i]; //storing index of max variablemaxindexvalue = i; } } //printing out maximum value to consoleSystem.out.println("Largest number in array is "+ max +" and its position in array is "+maxindexvalue); //variable for counting the number below the averageint numBelowAvg = 0; //variable for counting the number above the averageint numAboveAvg = 0;//for loop to find the number is below or above to the averagefor( i=0;i<100;i++) {//if the value is greater than averageif((double)arrayNum[i]<avg){//incrementing the value of numBelowAvgnumBelowAvg++;}//if the value is smaller than averageelse{ //incrementing the value of numAboveAvgnumAboveAvg++;}}//displaying the Numbers below the average:System.out.println("Numbers below the average: " + numBelowAvg); //displaying the Numbers above the average:System.out.println("Numbers above the average: " + numAboveAvg); }}
Hi I am coding with java. I am given the instructions:
- 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.
I coded all of this from the last time I got help from you guys. The instructions are just to give an idea of what I had to do. I really need help in breaking up my coding. Apparently I need to add methods in it and I'm not sure which method and where would work. Please show me how to do this. Thanks!
Here's my code:
//Brianna Fisher COMP 1000
//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
int i;
//declaring variable long type for storing the sum of all array elements
long sum=0;
//initiating random class
Random randNum = new Random();
//creating an array with integer type and array 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++)
{
//appointing random values to array
arrayNum[i]=randNum.nextInt(100);
}
//for loop to calculate the sum of all the array elements
for(i=0;i<100;i++)
{
// storing 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 sum by 100
double avg = (double)sum/100;
//calculating average of all arrays
System.out.println("Average of array:" +avg);
//assigning value of first index value to min
int min = arrayNum[0];
//intializing 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 its value can be assigned to the min variable
min = arrayNum[i];
//storing index value
minindexvalue = i;
}
}
//displaying the minimum value and its index value to console
System.out.println("Smallest number in array is "+ min +" and its position in array is "+ minindexvalue);
//assigning value of first array element to the max
int max = arrayNum[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(arrayNum[i]>max)
{
//assigning the value of array element to max variable
max = arrayNum[i];
//storing index of max variable
maxindexvalue = i;
}
}
//printing out maximum value to console
System.out.println("Largest number in array is "+ max +" and its position in array is "+maxindexvalue);
//variable for counting the number below the average
int numBelowAvg = 0;
//variable for counting the number above the average
int numAboveAvg = 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)arrayNum[i]<avg)
{
//incrementing the value of numBelowAvg
numBelowAvg++;
}
//if the value is smaller than average
else
{
//incrementing the value of numAboveAvg
numAboveAvg++;
}
}
//displaying the Numbers below the average:
System.out.println("Numbers below the average: " + numBelowAvg);
//displaying the Numbers above the average:
System.out.println("Numbers above the average: " + numAboveAvg);
}
}
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)