Java Reference
In-Depth Information
Write a test program that prompts the user to enter ten numbers, invokes this
method to return the index of the smallest element, and displays the index.
*6.11
(
Statistics: compute deviation
) Programming Exercise 5.37 computes the standard
deviation of numbers. This exercise uses a different but equivalent formula to
compute the standard deviation of
n
numbers.
n
n
mean
)
2
x
i
(
x
i
-
a
a
x
1
+
x
2
+
c
+
x
n
i
=
1
i
=
1
mean
=
=
deviation
=
Q
n
n
n
-
1
To compute the standard deviation with this formula, you have to store the indi-
vidual numbers using an array, so that they can be used after the mean is obtained.
Your program should contain the following methods:
/** Compute the deviation of double values */
public static double
deviation(
double
[] x)
/** Compute the mean of an array of double values */
public static double
mean(
double
[] x)
Write a test program that prompts the user to enter ten numbers and displays the
mean and standard deviation, as shown in the following sample run:
Enter ten numbers:
The mean is 3.11
The standard deviation is 1.55738
1.9 2.5 3.7 2 1 6 3 4 5 2
*6.12
(
Reverse an array
) The
reverse
method in Section 6.7 reverses an array by
copying it to a new array. Rewrite the method that reverses the array passed in the
argument and returns this array. Write a test program that prompts the user to
enter ten numbers, invokes the method to reverse the numbers, and displays the
numbers.
Section 6.9
*6.13
(
Random number chooser
) Write a method that returns a random number between
1 and 54, excluding the numbers passed in the argument. The method header is
specified as follows:
public static int
getRandom(
int
... numbers)
6.14
(
Computing gcd
) Write a method that returns the gcd of an unspecified number of
integers. The method header is specified as follows:
public static int
gcd(
int
... numbers)
Write a test program that prompts the user to enter five numbers, invokes the
method to find the gcd of these numbers, and displays the gcd.
Sections 6.10-6.12
6.15
(
Eliminate duplicates
) Write a method that returns a new array by eliminating the
duplicate values in the array using the following method header:
public static int
[] eliminateDuplicates(
int
[] list)