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

Want to see the full answer?

Check out a sample Q&A here
Blurred answer
Students who’ve seen this question also like:
Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Not helpful? See similar books
Database System Concepts
Database System Concepts
Introduction. 1PE
marketing sidebar icon
Want to see this answer and more?
Experts are waiting 24/7 to provide step-by-step solutions in as fast as 30 minutes!*
*Response times may vary by subject and question complexity. Median response time is 34 minutes for paid subscribers and may be longer for promotional offers.

Related Computer Science Q&A

Find answers to questions asked by students like you.

Q: This is for Java Programming   In my code, I'm missing a new line at the end of an array.  I'm not…

A: for (i = 0; i &lt; n; i++) array[i] = scnr.nextInt(); a = scnr.nextInt();…

Q: ODY OF Java program - THE checkWinner METHOD BELOW SO THAT THE GAME STOPS WHEN SOMEONE WINS, OR WHEN…

A: Please note as per the given displayRow(): void dispRow(int r) { System.out.println(board[r][0] +…

Q: WRITE THE BODY OF THE Java Program - checkWinner METHOD BELOW SO THAT THE GAME STOPS WHEN SOMEONE…

A: In the Tic-Tac-Toe game, you will see the approach of the game is implemented. In this game, two…

Q: WRITE THE BODY OF THE Java Program - checkWinner METHOD BELOW SO THAT THE GAME STOPS WHEN SOMEONE…

A: MUST MATCH OUTPUT below import java.util.Scanner; public class TicTacBoard { private char[][]…

Q: WRITE A JAVA PROGRAM Methods can be used to define reusable code and organize and simplify code.…

A: As given, I need to write a Java program that is having a static method sum which takes two int…

Q: I need this solved in java. The required testing inputs and their outputs are attached below. Here…

A: Click to see the answer

Q: Answer (JAVA LANGUAGE) 1) a. for (int i = 0; true; i++) System.out.println(a[i]); b. for (inti = 0;…

A: NOTE: As per the guidelines, answering only the first question. We have given an array a. We have…

Q: What is the output of the following Java program? import java.util.*; class ArrayGames { public…

A: A Java program contains an array of elements of size 5. The array elements are int type and a is the…

Q: Complete the following piece of java code, so that it could convert date to Julian number and Julian…

A: Julian Number - It is used for calculating days elapsed between two events. We have to implement two…

Q: debug this: Debugging Exercise 4-3, Farrell, Joyce, Java Programming, 9th edition, Cengage Learning…

A: A program after debugging is as follows, Note: A complete program is written below to test class…

Q: Write java method to take two integer arrays and one int size variables as parameters and check if…

A: HI THERE I AM ADDING JAVA CODE AS PER ABOVE REQUIREMENT BELOWPLEASE GO THROUGH IT THANK YOU

Q: Create a java program Using only one 2-D array (table) with equal odd sizes for its rows and…

A: // Java program for generating odd size magic squaresimport java.io.*;import java.util.*;class…

Q: Write a java program that contains a two-dimensional array of 2 rows and 3 columns. Find the sum of…

A: Summary :-We got the output.

Q: write a java program that contains 2 arrays, one for 10 students names and the other for their…

A: Logic: Accept names from the user and keep it names array which is one dimensional. Accept grades…

Q: Please add comments to my program. Thank you in advance! :) package examples; import…

A: Single line comments can be added in a java program using // and writing the comment. Multiple line…

Q: First, write a Java method issequence that takes as parameters a non-empty 2-dimensional array of…

A: The program is written in Java. Please find the source code in step 2.

Q: Write a Java method that takes a two-dimensional ragged array as input and uses that array to print…

A: The Answer is

Q: How can i make this data enter and enter as a table in java. Please dont use array import…

A: In Java, to print the results like a table structure we can use printf() method, it belongs to the…

Q: Write a java program to display the output like the one below using multi dimensional array. 1 2 3 6…

A: We need to have  5 rows to store 0-4 and 10 columns to store 0-9

Q: The maximum K-product of the array is the maximum product of any K length subsequence of the array.…

A: Given: You're given an array of N integers, and a number K.The maximum K-product of the array is the…

Q: The maximum K-product of the array is the maximum product of any K length subsequence of the array.…

A: Given: You're given an array of N integers, and a number K.The maximum K-product of the array is the…

Q: The maximum K-product of the array is the maximum product of any K length subsequence of the array.…

A: Given: You're given an array of N integers, and a number K.The maximum K-product of the array is the…

Q: The maximum K-product of the array is the maximum product of any K length subsequence of the array.…

A: Given: You're given an array of N integers, and a number K.The maximum K-product of the array is the…

Q: Write a Java program to take input an integer n which is the size of an array and then take input n…

A: Write a Java program to take input an integer n which is the size of an array and then take input n…

Q: Write and execute a program in Java at will read 3 test scores from the eyboard and store them in an…

A: Declare an array of size 3  Input three scores to array Display them

Q: Write a java program to test if the first and the last element of the array of integers are same.…

A: Required:- Approach:- check whether the first element is equal to the last element or not and print…

Q: cart off with something like the code below and implement readBoard with a scanf inside a nested…

A: I have written C code for the following question

Q: Write a code in Java that results like test 2&3

A: Given: Write a code in Java that results like test 2&amp;3

Q: This array method must be written by me. One at a time, shift all of the components to the right one…

A: An array is homogeneous data structure that stores data in linear order.  We can perform operations…

Q: This array method must be written by me. One at a time, shift all of the components to the right…

A: rightRotatebyOne(int arr[], int n)    {        int i, temp;        temp = arr[n-1];        for (i =…

Q: what is the output of the following java code segment? int array[]={1,2,3,4,5}; for(int i=0;…

A: Your s in the system.out.println line is in lowercase. I assume it's just a typing mistake. If it's…

Q: write java statement to shift the content of each cell of an integer array one place to the right,…

A: class RotateRight {     public static void main(String[] args) {            //Initialize array…

Q: 2. Write a JAVA program to print all perfect squares in the array given below. int []numbers =…

A: Given: Write a JAVA program to print all  perfect squares inn the array given below.

Q: In Java Add the following to the package below:    1.for or for...each or while loops. 2.Arrays…

A: Dear Student, In your question a while loop is already present so I am just adding a for loop and an…

Q: Write a java program to take input an array of size 5 from user and then find the maximum element in…

A: Requirements:- Write a java program to take input an array of size 5 from the user and then find the…

Q: Write a Java method called average which takes an array as parameter and returns the average value.…

A: // Main classpublic class Main{    // Method to find the average of number    public static double…

Q: Consider the method headings:             void funcOne(int [ ]  alpha,  int  size)…

A: Click to see the answer

Q: Create a java program which validates whether a given array alternates between positive and negative…

A: The solution for the above given question is given below:

Q: Write a Java program that will accept an array of size 5 and accept whole numbers from console (as…

A: Required:- Write a Java program that will accept an array of size 5 and accept whole numbers from…

Q: 17. Suppose that you had the following main program, what would the Customer Arraylist look like? -…

A: In step 1 I am giving the output of your program and in step 2 I am giving the ArrayList abstract…

Q: ****Answer question below: Write code in Java: - Make sure code is recursive. - Do not change…

A: Program in Java:   import java.util.*; import java.lang.*; import java.io.*; class DecimalToBinary {…

Q: Given an array below, write a Java program to take input an integer n from the user and print the…

A: Given an array below, write a Java program to take input an integer n from the user and print the…

Q: n Java, the statement x++ is exactly equivalent to x = x + 1. But if x is a char, it's not exactly…

A: note: These are 4 different programs that you need we are only allowed to solve one question in one…

Q: I need help with my spacing for my code. I attached what my code is expected to look like but i…

A: The program is written in Java. Added required spaces in output and formatted the source code also.…

Q: Write a Java program that computes the sum of two rational numbers given by the user. [Note: If two…

A: We need to read the input values a,x,b and y from keyboard ,compute the number and display the…

Q: Write a Java program that generates a random integer value between 1 and 15 and displays all the…

A: Sample output

Q: Write a java program to display on the screen a multiplication table from 1 to n; where n is an…

A: Given that  we have to make the program that can generate multiplication of the table till the given…

Q: Create java program with a declaration of int x = {1,2,3,4,5,6,7,8,9,10} that stores the value of…

A: We will retrieve the element at index 9 and then we will assign that element to index 1. The first…

Q: I need some help with this code import java.util.*; public class CarCareChoice2 { // Modify the…

A: NOTE: It is not specifically mentioned to modify the given code into what so the given code is…

Q: For each of the following pairs of concepts that are used in Java explain similarities and…

A: Simple Java Application:A basic Java program that is executed by the Java virtual machine on any…

Knowledge Booster
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
  • WRITE THE BODY OF Java program - THE checkWinner METHOD BELOW SO THAT THE GAME STOPS WHEN SOMEONE WINS, OR WHEN THE BOARD IS FULL. AS SHOWN IN THE SAMPLE OUTPUT AT THE BOTTOM. Code: import java.util.Scanner; public class TicTacBoard { private char[][] board; // 2-D array of characters private char curPlayer; // the player whose turn it is (X or O) // Constructor: board will be size x size public TicTacBoard(int size) { board = new char[size][size]; // initialize the board with all spaces: for(int row=0; row < board.length; row++) for(int col=0; col < board[row].length; col++) board[row][col] = ' '; curPlayer = 'X'; // X gets the first move } public void playGame() { display(); do { takeTurn(); display(); }while(!checkWinner()); } /////// display //////// // Display the current status of the board on the // screen, using hyphens (-) for horizontal lines // and pipes (|) for vertical lines. public void…
    Please make this java program work  Instruction: Write a test program that inputs, sorts, outputs Integer and Float. And call the isEqualTo method. import java.util.*; public class Generics <E>{       public static < E > void printArray( E inputArray[] ) {      // Display array elements      for( E element : inputArray) {         System.out.printf("%s ", element);      }      System.out.println();   }        public static < E extends Comparable<E> > void selectionSort(E array[]){        int size = array.length;                 for (int i = 0; i < size-1; i++){            // Find the minimum element            int min = i;            for (int j = i+1; j < size; j++)                if (array[j].compareTo(array[min]) < 0)                    min = j;             // Swap the found minimum element with the first element            E temp = array[min];            array[min] = array[i];            array[i] = temp;        }            }        public static <…
    This is for Java Programming   In my code, I'm missing a new line at the end of an array.  I'm not sure how to do this.  I get the correct output but am missing a newline at the end.  Please see attached image for clarity.  My code is below.   import java.util.Scanner; public class LabProgram {public static void main(String[] args) {Scanner scnr = new Scanner(System.in);int[] array=new int[20];int n;int a;int i;n=scnr.nextInt();for(i = 0; i < n; i++)array[i]=scnr.nextInt();a=scnr.nextInt();for(i = 0; i < n; i++){if(array[i]<=a)System.out.print(array[i] + " ");}}}
  • Using Jcreator, open, compile, and run java and observe its runtime. Write your observation regarding how encapsulation works for the program and the data it processed. Limit your paper to a single paragraph with at least 50 words or five (5) sentences. Source Code: public class FindAbsoluteValueExample {     public static void main(String args[]) {      Integer a = -8;      double d = -100;      float f = -90;       System.out.println(Math.abs(a));      System.out.println(Math.abs(d));           System.out.println(Math.abs(f));       }}
    Using Jcreator, open, compile, and run java and observe its runtime. Write your observation regarding how encapsulation works for the program and the data it processed. Limit your paper to a single paragraph with at least 50 words or five (5) sentences.   Source code: public class EncapTest {   private String name;   private String idNum;   private int age;    public int getAge() {      return age;   }    public String getName() {      return name;   }    public String getIdNum() {      return idNum;   }    public void setAge( int newAge) {      age = newAge;   }    public void setName(String newName) {      name = newName;   }    public void setIdNum( String newId) {      idNum = newId;   }} public class RunEncap {    public static void main(String args[]) {      EncapTest encap = new EncapTest();      encap.setName("James");      encap.setAge(20);      encap.setIdNum("12343ms");       System.out.print("Name : " + encap.getName() + " Age : " + encap.getAge());   }}
    Write a java program, I believe the first array should only be changed. In the main method:   Create an array with the values: 99, 55, 87, 21, 3, using any method   Create a second array   Copy the elements of the first array to the second   Change an element of the first array.   Print both arrays
  • READY CAREFULLY Java add comment to code, please write your test-cases on how you would test your solution assumptions and hence your code. Example of cases to be tested for are like : What if the array input which is expected does not exist - that is , input is a null. How should your code handle such a situation ? Maybe output some message like ”Null input case, so no output”? What if the length of the array is one ?....so on and so forth. Please Remember : Although, written as comments - You will address your test cases in the form of code and not prose In this assignment you are required to do a programs which takes as input two sorted arrays and returns a new array containing the elements found in both the sorted arrays. It is alright if the input arrays have duplicates, but the returned array should be duplicate free! Below is how the arrays are represented   ARRAY1[] = [1, 5, 6, 6, 9, 9, 9, 11, 11, 21] Here length of ARRAY1 is m.   ARRAY2[] = [6, 6, 9, 11, 21, 21, 21] Here…
    First, write a Java method isSequence that takes as parameters a non-empty 2-dimensional array of integers. The method checks whether the elements of the array are consecutive or not.Second, write a java methods printArray(int[][]a) that writes the elements of an array passed in parameter to the standard output.Finally, use the following main method to test your different methods:
    I need a help in making a method that will Input a text that will be converted to Huffman code and Input a Huffman code that will be converted to its text equivalent.You can try this sample Character input: HAAHAABAAACACAAAABABABEBEBBAABEEBBCCCCCAAAAAAACCCDDDDDDAAADDDDDEEEEEEDDADDDADDEEEEEEEECCCEEEEEEEEEEDDEEEEEEEEEEBBEEEEEFFGGHAHHEEHHA   Huffman.java import java.util.PriorityQueue;import java.util.Scanner;import java.util.Comparator;import java.util.ArrayList; class HuffmanNode {   int data;   char c;   HuffmanNode left;   HuffmanNode right;} class MyComparator implements Comparator<HuffmanNode> {   public int compare(HuffmanNode x, HuffmanNode y) {       return x.data - y.data;   }} public class Huffman {   public static void printCode(HuffmanNode root, String s) {       if (root.left == null && root.right == null && Character.isLetter(root.c)) {           System.out.println(s + "tttt"+ s.length());           return;       }        printCode(root.left, s + "0");…
    • SEE MORE QUESTIONS
    Recommended textbooks for you
  • Database System Concepts
    Computer Science
    ISBN:9780078022159
    Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
    Publisher:McGraw-Hill Education
    Starting Out with Python (4th Edition)
    Computer Science
    ISBN:9780134444321
    Author:Tony Gaddis
    Publisher:PEARSON
    Digital Fundamentals (11th Edition)
    Computer Science
    ISBN:9780132737968
    Author:Thomas L. Floyd
    Publisher:PEARSON
  • C How to Program (8th Edition)
    Computer Science
    ISBN:9780133976892
    Author:Paul J. Deitel, Harvey Deitel
    Publisher:PEARSON
    Database Systems: Design, Implementation, & Manag...
    Computer Science
    ISBN:9781337627900
    Author:Carlos Coronel, Steven Morris
    Publisher:Cengage Learning
    Programmable Logic Controllers
    Computer Science
    ISBN:9780073373843
    Author:Frank D. Petruzella
    Publisher:McGraw-Hill Education
  • Database System Concepts
    Computer Science
    ISBN:9780078022159
    Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
    Publisher:McGraw-Hill Education
    Starting Out with Python (4th Edition)
    Computer Science
    ISBN:9780134444321
    Author:Tony Gaddis
    Publisher:PEARSON
    Digital Fundamentals (11th Edition)
    Computer Science
    ISBN:9780132737968
    Author:Thomas L. Floyd
    Publisher:PEARSON
    C How to Program (8th Edition)
    Computer Science
    ISBN:9780133976892
    Author:Paul J. Deitel, Harvey Deitel
    Publisher:PEARSON
    Database Systems: Design, Implementation, & Manag...
    Computer Science
    ISBN:9781337627900
    Author:Carlos Coronel, Steven Morris
    Publisher:Cengage Learning
    Programmable Logic Controllers
    Computer Science
    ISBN:9780073373843
    Author:Frank D. Petruzella
    Publisher:McGraw-Hill Education