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[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);

Question
Asked Nov 3, 2019
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[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);

 

 

check_circle

Expert Answer

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[0];

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_outline

Image Transcriptionclose

The 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

Check out a sample Q&A here.

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.

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: Consider the window size is 10, bandwidth is 1500 bps, transmission delay is 2 ms atpropagation dela...

A: Given information:

question_answer

Q: Draw a decision tree and find the number of key comparisons in the worst and average cases for the t...

A: Decision tree (enhanced bubble sort):

question_answer

Q: Python 3.7.4 Given four files named asiasales2009.txt, europesales2009.txt, africasales2009.txt, and...

A: Statements for creating objects:#for first file asiasales2009.txt for writingasia = open("asiasales2...

question_answer

Q: Question 4: What does the following code output? vector icecream ( 10, "Vanilla" ); icecream.insert...

A: The complete source code for the given question is given below along with the output.Note: If the he...

question_answer

Q: Hi, I am required to: Create an array of 100 integers using a random generator. ( 1 for loop) Provi...

A: The given java program will follow the following rubrics:Importing essential header files.Creating a...

question_answer

Q: Use the Design Recipe to write a function weighted_total(number_list,weights) that consumes a list o...

A: The given list of numbers is [1, 2, 3].The given weights are [0.1, 0.5, 0.4].weighted_total(number_l...

question_answer

Q: WAHT IS A BYZANTINE GENERALS PROBLEM OF DIGITAL CASH TRANSACTIONS?

A: The Bitcoin protocol provides a means for digital currency transactions, so that everyone can decide...

question_answer

Q: Please put into SOP formxz + (xy + ~z)

A: A Boolean expression is said to be in the Canonical form either it has purely min-terms or max-terms...

question_answer

Q: Write a simplified expression for the Boolean function defined by the following Kmap.

A: Identify only 1’s in the kmap group.Find the largest group of 1’s.In three varible a group can have ...