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[0]) { 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);
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[0])
{
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);
Trending now
This is a popular solution!
Step by step
Solved in 6 steps with 4 images