Java Reference
In-Depth Information
The formula for comp
uting the distance between two points
(x1, y1, z1)
and
(x2, y2, z2)
is
x
1
)
2
y
1
)
2
z
1
)
2
.
2
(
x
2
-
+
(
y
2
-
+
(
z
2
-
**8.8
(
All closest pairs of points
) Revise Listing 8.3, FindNearestPoints.java, to
display all closest pairs of points with the same minimum distance. Here is
a sample run:
Enter the number of points: 8
Enter 8 points: 0 0 1 1 -1 -1 2 2 -2 -2 -3 -3 -4 -4 5 5
The closest two points are (0.0, 0.0) and (1.0, 1.0)
The closest two points are (0.0, 0.0) and (-1.0, -1.0)
The closest two points are (1.0, 1.0) and (2.0, 2.0)
The closest two points are (-1.0, -1.0) and (-2.0, -2.0)
The closest two points are (-2.0, -2.0) and (-3.0, -3.0)
The closest two points are (-3.0, -3.0) and (-4.0, -4.0)
Their distance is 1.4142135623730951
***8.9
(
Game: play a tic-tac-toe game
) In a game of tic-tac-toe, two players take turns
marking an available cell in a 3
3 grid with their respective tokens (either
X or O). When one player has placed three tokens in a horizontal, vertical, or
diagonal row on the grid, the game is over and that player has won. A draw (no
winner) occurs when all the cells on the grid have been filled with tokens and
neither player has achieved a win. Create a program for playing tic-tac-toe.
*
The program prompts two players to enter an X token and O token alter-
nately. Whenever a token is entered, the program redisplays the board on the
console and determines the status of the game (win, draw, or continue). Here
is a sample run:
——————-——————
| | | |
——————-——————
| | | |
——————-——————
| | | |
——————-——————
Enter a row (0, 1, or 2) for player X: 1
Enter a column (0, 1, or 2) for player X: 1
——————-——————
| | | |
——————-——————
| | X | |
——————-——————
| | | |
——————-——————
Enter a row (0, 1, or 2) for player O: 1
Enter a column (0, 1, or 2) for player O: 2
——————-——————
| | | |
——————-——————
| | X | O |
——————-——————
| | | |
——————-——————
Search WWH ::
Custom Search