# Im trying to write code for java where the random array that I have genreated are used and then list the int above and below the average... here is what I have but I dont think its correct.  import java.util.Random;import java.util.Scanner;  public class Troubleshooting {//Data Memberspublic static final int N = 100; public static final int SEED = -1;public static int sum;public static int min;public static int max;public static int avg;public static int greater;public static int smaller;  //Main Functionpublic static void main(String[] args){ sum = 0;int ary[] = new int [N]; Random rndGen = new Random(SEED);  //Populate for(int i = 0; i < N; i++){ary[i] = rndGen.nextInt(101);} //Calculate Sum of Arrayfor(int i = 0; i < N; i++){sum += ary[i];} //Calculate Average of Arraydouble avg = (double)sum/ (double)N; //Minimum number in Arrayfor(int i = 0; i < N; i++){if(min > ary[i]){min = ary[i];} }  //Max Number In Arrayint index = 0;for(int i = 0; i < N; i++){//if(max = ary){max = ary[i];index = i;} }  for (int i = 0; i < N; i++)          if (greater > avg)             greater = ary[i]; for (int i = 0; i < N; i++)          if (smaller < avg)             smaller = ary[i]; System.out.println("The Sum of the Array: "+sum);System.out.println("The Average is: " +avg);System.out.println("The Max Array is: " +max);System.out.println("The Min Array is: " +min);System.out.println("The bellow Average: " +smaller);System.out.println("The above Average: " +greater);

Question
21 views

Im trying to write code for java where the random array that I have genreated are used and then list the int above and below the average... here is what I have but I dont think its correct.

import java.util.Random;

import java.util.Scanner;

public class Troubleshooting

{

//Data Members

public static final int N = 100;

public static final int SEED = -1;

public static int sum;

public static int min;

public static int max;

public static int avg;

public static int greater;

public static int smaller;

//Main Function

public static void main(String[] args)

{

sum = 0;

int ary[] = new int [N];

Random rndGen = new Random(SEED);

//Populate

for(int i = 0; i < N; i++)

{

ary[i] = rndGen.nextInt(101);

}

//Calculate Sum of Array

for(int i = 0; i < N; i++)

{

sum += ary[i];

}

//Calculate Average of Array

double avg = (double)sum/ (double)N;

//Minimum number in Array

for(int i = 0; i < N; i++)

{

if(min > ary[i])

{

min = ary[i];

}

}

//Max Number In Array

int index = 0;

for(int i = 0; i < N; i++)

{

//if(max = ary)

{

max = ary[i];

index = i;

}

}

for (int i = 0; i < N; i++)

if (greater > avg)

greater = ary[i];

for (int i = 0; i < N; i++)

if (smaller < avg)

smaller = ary[i];

System.out.println("The Sum of the Array: "+sum);

System.out.println("The Average is: " +avg);

System.out.println("The Max Array is: " +max);

System.out.println("The Min Array is: " +min);

System.out.println("The bellow Average: " +smaller);

System.out.println("The above Average: " +greater);

check_circle

Step 1

Following is the source code with modifications in it. Comments have been added wherever the modifications have been done.

Step 2

Source Code

import java.util.Random;

import java.util.Scanner;

public class Troubleshooting

{

//Data Members

public static final int N = 100;

public static final int SEED = -1;

public static int sum;

public static int min;

public static int max=0;

public static int avg;

public static int greater;

public static int smaller;

//Main Function

public static void main(String[] args)

{

//declare the variables

int count=0;

int count1=0;

sum = 0;

int ary[] = new int [N];

Random rndGen = new Random();

//Populate

for(int i = 0; i < N; i++)

{

ary[i] = rndGen.nextInt(101);

}

//print the generated random numbers

System.out.println("The random numbers are:");

for (int i = 0; i < ary.length; i++) {

System.out.println(ary[i]);

}

//Calculate Sum of Array

for(int i = 0; i < N; i++)

{

sum += ary[i];

}

//Calculate Average of Array

double avg = (double)sum/ (double)N;

//Minimum number in Array

min=ary;

for(int i = 0; i < N; i++)

{

if( ary[i]<min) // condition to check min number

{

min = ary[i];

}

}

//Max Number In Array

for(int i = 0; i < N; i++)

{

if( ary[i]>max) // condition to check max number

max = ary[i];

}

for (int i = 0; i < N; i++)

{

if (ary[i] > avg)

{

greater = ary[i];

count++;   //increase the count value if number is greater than average

}

}

for (int i = 0; i < N; i++)

{

if (ary[i] < avg)

{

smaller = ary[i];

count1++;     //increase the value of count1 if the number is smaller than the average

}

}

System.out.println("The Sum of the Array: "+sum);

System.out.println("The Average is: " +avg);

System.out.println("The Max Array is: " +max);

System.out.println("The Min Array is: " +min);

System.out.println("The bellow Average: " +count1);

System.out.println("The above Average: " +count);

}

}

Step 3

Output

... help_outlineImage TranscriptioncloseThe random numbers are: 26 1 91 74 73 45 6 93 36 79 44 75 74 82 93 74 26 83 81 15 62 21 10 21 24 75 79 39 81 25 fullscreen

### Want to see the full answer?

See Solution

#### Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in 