
Concept explainers
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 nowThis is a popular solution!
Step by stepSolved in 6 steps with 4 images

- I need help with this problem in Java : import java.util.Scanner; public class LabProgram { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int num1; int num2; int num3; int num4; /* Type your code here. */ }}arrow_forwardThis is my program. I need help with the math. import java.util.*;import javax.swing.JOptionPane;public class Craps { public static void main(String[] args) { int Bet, Die; int WinC = 0, LossC = 0, GameC = 0, GameN = 1; double startingBal = 0, curBal = 0; double balD, balDe, balDec, balI, balIn, balInc; char Answer = '\0'; Scanner crapsGame = new Scanner(System.in); System.out.println("Welcome to the Craps Game"); curBal = StartingBal(startingBal); System.out.println("Your starting balance is: $" + curBal); do { System.out.println("Please input your bet for the game>> "); Bet = crapsGame.nextInt(); System.out.println("Game #" + GameN + " Starting with bet of: $" + Bet ); if (Bet < 1 || Bet > curBal) { System.out.println("Invalid bet – Your balance is only: $" + curBal); while (Bet < 1 || Bet > curBal)…arrow_forwardWrite a java program (class) called Grades to do the following. Must use an array. Ask the user for 20 grades. Get from the user each grade and fill an array with the grades. Find the average of the elements of the array. Print how many grades are smaller than the average. To get you started, your program code will begin as follows: import java. util. *; //includes Scanner public class Grades { public static void main(String[] args) { //begins main methodarrow_forward
- 3. Write a Java program to test if an array contains a specific value. PS: Please upload the output and say the logic behind it. Thank you!arrow_forwardHow do I code: public static void rotateElements(int[] arr, int rotationCount) public static void reverseArray(int[] arr) In Java?arrow_forwardNeed some help with a Java problemarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





