Java Reference
In-Depth Information
Write a test program that prompts the user to enter a list of characters in one line,
and a character, and displays the number of occurrences of the character in the list.
Sections 18.6-18.10
*18.18
( Tower of Hanoi ) Modify Listing 18.8, TowerOfHanoi.java, so that the program
finds the number of moves needed to move n disks from tower A to tower B.
( Hint : Use a static variable and increment it every time the method is called.)
*18.19
( Sierpinski triangle ) Revise Listing 18.9 to develop a program that lets the user
use the + and - buttons to increase or decrease the current order by 1 , as shown
in FigureĀ 18.12a. The initial order is 0 . If the current order is 0 , the Decrease
button is ignored.
(a)
(b)
F IGURE 18.12
(a) Programming Exercise 18.19 uses the + and - buttons to increase or
decrease the current order by 1 . (b) Programming Exercise 18.20 draws ovals using a recur-
sive method.
*18.20
( Display circles ) Write a Java program that displays ovals, as shown in Fig-
ureĀ 18.12b. The circles are centered in the pane. The gap between two adjacent
circles is 10 pixels, and the gap between the border of the pane and the largest
circle is also 10 .
*18.21
( Decimal to binary ) Write a recursive method that converts a decimal number
into a binary number as a string. The method header is:
public static String dec2Bin( int value)
Write a test program that prompts the user to enter a decimal number and dis-
plays its binary equivalent.
*18.22
( Decimal to hex ) Write a recursive method that converts a decimal number into
a hex number as a string. The method header is:
public static String dec2Hex( int value)
Write a test program that prompts the user to enter a decimal number and dis-
plays its hex equivalent.
*18.23
( Binary to decimal ) Write a recursive method that parses a binary number as a
string into a decimal integer. The method header is:
public static int bin2Dec(String binaryString)
Write a test program that prompts the user to enter a binary string and displays
its decimal equivalent.
 
 
Search WWH ::




Custom Search