Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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(

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) //1st method

Write a method that finds the smallest element in this array of double values using the following

header:

public static double min( double [] array) //2nd method

Write a test program that prompts the user to enter 10 double values, invokes the 1st method, then displays the average value. In addition, invokes 2nd method to return the minimum value, and displays the minimum value.

So I have figured out the how to find the average of the double and int values but i cannot figure out how to find the minimum. i have put the method for this on top commented as 2nd method

java.util.Scanner in = new java.util.Scanner(System.in); double[] vals = new double[10]; System.out.print("Please enter to double values: ");

for (int i = 0; i < 10; i++) vals[i] = in.nextDouble(); System.out.printf("The average is: %.2f", average(vals)); }

public static int average(int[] array) { int sum = 0; for (int val : array) sum += val; return sum / array.length; }

public static double average(double[] array) { double sum = 0.0; for (double val : array) sum += val; return sum / array.length; } public static double min(double[] array) { double min = array[0]; // The minimum value for (double i: array) { if (i < min) min = i; } return min; }

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 2012 Proceedings Part 2 Lnai 7197

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284892, 978-3642284892

More Books

Students also viewed these Databases questions