Java Reference
In-Depth Information
objects to be picked at least once. A variation of the problem is to pick cards from
a shuffled deck of 52 cards repeatedly and find out how many picks are needed
before you see one of each suit. Assume a picked card is placed back in the deck
before picking another. Write a program to simulate the number of picks needed
to get four cards from each suit and display the four cards picked (it is possible a
card may be picked twice). Here is a sample run of the program:
Queen of Spades
5 of Clubs
Queen of Hearts
4 of Diamonds
Number of picks: 12
7.25
( Algebra: solve quadratic equations ) Write a method for solving a quadratic
equation using the following header:
public static int solveQuadratic( double [] eqn, double [] roots)
The coefficients of a quadratic equation ax 2
0 are passed to the
array eqn and the real roots are stored in roots. The method returns the num-
ber of real roots. See Programming Exercise 3.1 on how to solve a quadratic
equation.
Write a program that prompts the user to enter values for a , b , and c and displays
the number of real roots and all real roots.
+
bx
+
c
=
7.26
( Strictly identical arrays ) The arrays list1 and list2 are strictly identical
if their corresponding elements are equal. Write a method that returns true if
list1 and list2 are strictly identical, using the following header:
public static boolean equals( int [] list1, int [] list2)
Write a test program that prompts the user to enter two lists of integers and dis-
plays whether the two are strictly identical. Here are the sample runs. Note that
the first number in the input indicates the number of the elements in the list. This
number is not part of the list.
Enter list1: 5 2 5 6 1 6
Enter list2: 5 2 5 6 1 6
Two lists are strictly identical
Enter list1: 5 2 5 6 6 1
Enter list2: 5 2 5 6 1 6
Two lists are not strictly identical
7.27
( Identical arrays ) The arrays list1 and list2 are identical if they have the
same contents. Write a method that returns true if list1 and list2 are identi-
cal, using the following header:
public static boolean equals( int [] list1, int [] list2)
 
Search WWH ::




Custom Search