Java Reference
In-Depth Information
The program enables the user to place or remove a mark on a cell. A path
consists of adjacent unmarked cells. Two cells are said to be adjacent if they
are horizontal or vertical neighbors, but not if they are diagonal neighbors.
■
The path does not contain cells that form a square. The path in Figure 18.13b,
for example, does not meet this condition. (The condition makes a path easy
to identify on the board.)
■
**18.27
(
Koch snowflake fractal
) The text presented the Sierpinski triangle fractal. In
this exercise, you will write a program to display another fractal, called the
Koch
snowflake
, named after a famous Swedish mathematician. A Koch snowflake is
created as follows:
1. Begin with an equilateral triangle, which is considered to be the Koch fractal
of order (or level)
0
, as shown in Figure 18.14a.
2. Divide each line in the shape into three equal line segments and draw an out-
ward equilateral triangle with the middle line segment as the base to create a
Koch fractal of order
1
, as shown in Figure 18.14b.
3. Repeat Step 2 to create a Koch fractal of order
2
,
3
, . . . , and so on, as shown
in Figure 18.14c-d.
(a)
(b)
(c)
(d)
F
IGURE
18.14
A Koch snowflake is a fractal starting with a triangle.
**18.28
(
Nonrecursive directory size
) Rewrite Listing 18.7, DirectorySize.java, without
using recursion.
*18.29
(
Number of files in a directory
) Write a program that prompts the user to enter a
directory and displays the number of the files in the directory.
**18.30
(
Find words
) Write a program that finds all occurrences of a word in all the files
under a directory, recursively. Pass the parameters from the command line as
follows:
VideoNote
Search a string in a directory
java Exercise18_30 dirName word
**18.31
(
Replace words
) Write a program that replaces all occurrences of a word with a
new word in all the files under a directory, recursively. Pass the parameters from
the command line as follows:
java Exercise18_31 dirName oldWord newWord
***18.32
(
Game: Knight's Tour
) The Knight's Tour is an ancient puzzle. The objective is
to move a knight, starting from any square on a chessboard, to every other square
once, as shown in Figure 18.15a. Note that the knight makes only L-shaped
moves (two spaces in one direction and one space in a perpendicular direc-
tion). As shown in Figure 18.15b, the knight can move to eight squares. Write
Search WWH ::
Custom Search