Java Reference
In-Depth Information
*11.9
(
Largest rows and columns
) Write a program that randomly fills in
0
s and
1
s
into an n-by-n matrix, prints the matrix, and finds the rows and columns with the
most
1
s. (
Hint
: Use two
ArrayList
s to store the row and column indices with
the most
1
s.) Here is a sample run of the program:
Enter the array size n: 4
The random array is
0011
0011
1101
1010
The largest row index: 2
The largest column index: 2, 3
11.10
(
Implement
MyStack
using inheritance
) In ListingĀ 11.10
,
MyStack
is imple-
mented using composition. Define a new stack class that extends
ArrayList
.
Draw the UML diagram for the classes and then implement
MyStack
. Write
a test program that prompts the user to enter five strings and displays them in
reverse order.
11.11
(
Sort
ArrayList
) Write the following method that sorts an
ArrayList
of
numbers:
public static void
sort(ArrayList<Integer> list)
Write a test program that prompts the user to enter 5 numbers, stores them in an
array list, and displays them in increasing order.
11.12
(
Sum
ArrayList
) Write the following method that returns the sum of all num-
bers in an
ArrayList
:
public static double
sum(ArrayList<Double> list)
Write a test program that prompts the user to enter 5 numbers, stores them in an
array list, and displays their sum.
*11.13
(
Remove duplicates
) Write a method that removes the duplicate elements from
an array list of integers using the following header:
public static void
removeDuplicate(ArrayList<Integer> list)
Write a test program that prompts the user to enter 10 integers to a list and dis-
plays the distinct integers separated by exactly one space. Here is a sample run:
Enter ten integers: 34 5 3 5 6 4 33 2 2 4
The distinct integers are 34 5 3 6 4 33 2
11.14
(
Combine two lists
) Write a method that returns the union of two array lists of
integers using the following header:
public static
ArrayList<Integer> union(
ArrayList<Integer> list1, ArrayList<Integer> list2)
Search WWH ::
Custom Search