Java Reference
In-Depth Information
{ b[h]= 0; }
zeroEven(b, h + 1);
SR10.
if
(h > k) {
return
; }
if
(b[h] == 5) {
System.out.println(5);
return
;
}
printIf5(b, h + 1, k);
SR11.
if
(s.length() == 0) {
return
s; }
return
s.charAt(0) + s.charAt(0) + dup(s.substring(1));
SR12.
if
(s.length() == 0) {
return
0; }
return
((
int
) s.charAt(0) - (
int
) '0')
+ sumChars(s.substring(1));
SR13.
if
(s.length() == 0) {
return
s; }
return
Character.toLowerCase(s.charAt(0))
+ lowerCase(s.substring(1));
SR14.
if
(s.length() <= 1) {
return
s; }
return
s.charAt(1)
+ (s.charAt(0) + swapPairs(s.substring(2)));
SR15.
if
(s.length() <= 1) {
return
""; }
return
s.charAt(2) + removeE(s.substring(3));
15.2
Some interesting recursive methods
15.2.1
Tiling Elaine's kitchen
Elaine has a 16-foot by 16-foot kitchen (see Fig. 15.4). In one of the squares of
this kitchen is a one-foot by one-foot refrigerator. Elaine would like the floor of
the kitchen, except for the refrigerator square, tiled with L-shaped tiles, each of
which is a 2-foot by 2-foot square with one corner removed. Can Elaine's kitchen
be tiled with such tiles? How should we go about it?
Activity
15-3.1
16
the four kinds of tiles
16
refrigerator, in one of the squares
Figure 15.4:
Elaine's kitchen and the tiles
Search WWH ::
Custom Search