Java Reference
In-Depth Information
( Hint : Use a two-dimensional array borrowers to represent loans.
borrowers[i][j] indicates the loan that bank i loans to bank j . Once bank j
becomes unsafe, borrowers[i][j] should be set to 0 .)
*7.18
( Shuffle rows ) Write a method that shuffles the rows in a two-dimensional int
array using the following header:
public static void shuffle( int [][] m)
Write a test program that shuffles the following matrix:
int [][] m = {{ 1 , 2 }, { 3 , 4 }, { 5 , 6 }, { 7 , 8 }, { 9 , 10 }};
**7.19
( Pattern recognition: four consecutive equal numbers ) Write the following
method that tests whether a two-dimensional array has four consecutive numbers
of the same value, either horizontally, vertically, or diagonally.
public static boolean isConsecutiveFour( int [][] values)
Write a test program that prompts the user to enter the number of rows and
columns of a two-dimensional array and then the values in the array and displays
true if the array contains four consecutive numbers with the same value. Other-
wise, display false. Here are some examples of the true cases:
0 1 0 3 1 6 1
0 1 6 8 6 0 1
5 6 2 1 8 2 9
6 5 6 1 1 9 1
1 3 6 1 4 0 7
3 3 3 3 4 0 7
0 1 0 3 1 6 1
0 1 6 8 6 0 1
5 5 2 1 8 2 9
6 5 6 1 1 9 1
1 5 6 1 4 0 7
3 5 3 3 4 0 7
0 1 0 3 1 6 1
0 1 6 8 6 0 1
5 6 2 1 6 2 9
6 5 6 6 1 9 1
1 3 6 1 4 0 7
3 6 3 3 4 0 7
0 1 0 3 1 6 1
0 1 6 8 6 0 1
9 6 2 1 8 2 9
6 9 6 1 1 9 1
1 3 9 1 4 0 7
3 3 3 9 4 0 7
***7.20
( Game: connect four ) Connect four is a two-player board game in which the
players alternately drop colored disks into a seven-column, six-row vertically
suspended grid, as shown below.
The objective of the game is to connect four same-colored disks in a row, a col-
umn, or a diagonal before your opponent can do likewise. The program prompts
two players to drop a red or yellow disk alternately. In the preceding figure, the
red disk is shown in a dark color and the yellow in a light color. Whenever a disk
is dropped, the program redisplays the board on the console and determines the
status of the game (win, draw, or continue). Here is a sample run:
 
Search WWH ::




Custom Search