Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question

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

 

 

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
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
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education