Java Reference
In-Depth Information
Enter list1:
Enter list2:
Two lists are not strictly identical
5 2 5 6 6 1
5 2 5 6 1 6
6.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 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 identical. Here are the sample runs. Note that the first
number in the input indicates the number of the elements in the list.
Enter list1:
Enter list2:
Two lists are identical
5 2 5 6 6 1
5 5 2 6 1 6
Enter list1:
Enter list2:
Two lists are not identical
5 5 5 6 6 1
5 2 5 6 1 6
*6.28
( Math: combinations ) Write a program that prompts the user to enter 10 integers
and displays all combinations of picking two numbers from the 10.
*6.29
( Game: pick four cards ) Write a program that picks four cards from a deck of 52
cards and computes their sum. An Ace, King, Queen, and Jack represent 1, 13, 12,
and 11, respectively. Your program should display the number of picks that yields
the sum of 24.
*6.30
( Pattern recognition: consecutive four equal numbers ) Write the following
method that tests whether the array has four consecutive numbers with the same
value.
VideoNote
Consecutive four
public static boolean isConsecutiveFour( int [] values)
Write a test program that prompts the user to enter a series of integers and displays
true if the series contains four consecutive numbers with the same value. Other-
wise, display false. Your program should first prompt the user to enter the input
size—i.e., the number of values in the series.
**6.31
( Merge two sorted lists ) Write the following method that merges two sorted lists
into a new sorted list.
public static int [] merge( int [] list1, int [] list2)
Implement the method in a way that takes list1.length + list2.length
comparisons. Write a test program that prompts the user to enter two sorted lists
and displays the merged list. Here is a sample run. Note that the first number in the
input indicates the number of the elements in the list.
 
Search WWH ::




Custom Search