A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 one year ago
Average an array)
Write two overloaded methods that return the average of an array with the following headers:
public static int average(int[] array)
public static double average(double[] array)
Write a test program that random generate ten integers between 0 – 100, and ten double values between 0 – 50. Invokes both methods, and displays all values and the average values. (All double numbers will be displayed with twodigit decimal places.)
as i have done somewhat but, still there is error in it. please solve this problem according to the question.
anonymous
 one year ago
Average an array) Write two overloaded methods that return the average of an array with the following headers: public static int average(int[] array) public static double average(double[] array) Write a test program that random generate ten integers between 0 – 100, and ten double values between 0 – 50. Invokes both methods, and displays all values and the average values. (All double numbers will be displayed with twodigit decimal places.) as i have done somewhat but, still there is error in it. please solve this problem according to the question.

This Question is Open

anonymous
 one year ago
Best ResponseYou've already chosen the best response.0``` //generation import java.util.Random; Random rng = new Random(); //random number generator (int) for(int i=0;i<10;i++) array[i] = rng.nextInt(101); //nextInt(n) generates an int from 0...n1 ``` similarly use rng.nextDouble which generates a number from [0,1) ``` display(T arr) { //loop over arr size //print each element } avg(T arr) { sum=0 loop over array accumulate elements in arrayy and store in sum divide by size of collection } ```

anonymous
 one year ago
Best ResponseYou've already chosen the best response.0I wrote the functions that you will need. The rest you can easily do. https://gist.github.com/AlexeyNosych/cc23e780d58c5a67f279

anonymous
 one year ago
Best ResponseYou've already chosen the best response.0Thanx for your kind help but m still confused... i did something which is as follows ackage intdouble; /** * * @author JAY */ import static java.lang.Math.random; import java.util.Scanner; import java.util.Random; //import java.util.Random.nextint; public class IntDouble { public static int average(int[] array) { int sum = 0; int average = 0; for (int i = 0; i < array.length; i++) { random rn= new random(); sum += random.nextInt(100); } average = sum / array.length; return average; } public static double average(double[] array) { double sum = 0; double average = 0; for (int i = 0; i < 5; i++) { sum += random.nextInt(50); } average = sum / array.length; return average; } public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter Integer values: "); int array1[] = new int[4]; for (int i = 0; i < array1.length; i++) { array1[i] = input.nextInt(); } int avg1 = average(array1); System.out.println("Average of First Array: " + avg1); System.out.println(); System.out.print("Enter Ten Double Values: "); double array2[] = new double[10]; for (int i = 0; i < array1.length; i++) { array2[i] = input.nextDouble(); } double avg2 = average(array2); System.out.println("Average of Second Array: " + avg2); } }

anonymous
 one year ago
Best ResponseYou've already chosen the best response.0This is waht i did.. but it ask for number.. but i want to genrate the number randomly for both integer and double and and last it has to show those 10 random numbers.. Please complete this program... i am posting it again /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools  Templates * and open the template in the editor. */ package intdouble; /** * * @author JAY */ import static java.lang.Math.random; import java.util.Scanner; import java.util.Random; //import java.util.Random.nextint; public class IntDouble { public static int IntDouble(int[] array) { int sum = 0; int average = 0; Random rn= new Random(); for (int i = 0; i < array.length; i++) array[i] = rn.nextInt(101); sum += Random.nextInt(100); average = sum / array.length; return average; } public static double IntDouble(double[] array) { double sum = 0; double average = 0; { Random rn= new Random(); for (int i = 0; i < 5; i++) array[i] = rn.nextInt(101); //sum += Random.nextInt(50); } average = sum / array.length; return average; } public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter Integer values: "); int array1[] = new int[10]; for (int i = 0; i < array1.length; i++) { array1[i] = input.nextInt(); } int avg1 = IntDouble(array1); System.out.println("Average of First Array: " + avg1); System.out.println(); System.out.print("Enter Ten Double Values: "); double array2[] = new double[10]; for (int i = 0; i < array1.length; i++) { array2[i] = input.nextDouble(); } double avg2 = IntDouble(array2); System.out.println("Average of Second Array: " + avg2); } }
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.