RECURSION
Name _
THE THREE RULES OF RECURSION :
Approach every recursive problem as if it were a journey; if you follow these rules, you will complete the journey
successfully.
RULE 1:
Find out how to take just one step
RULE 2:
Break each journey down int
Chapter 13 Review Exercise Solutions
R13.1
Recursion
Recursion solves a problem by using the solution of the same problem with simpler
values.
Iteration
Iteration uses some form of a loop (for loop, while loop) to solve a problem.
Infinite recursion
Infin
Chapter 10 Review Exercise Solutions
R10.1
SavingsAccount b = new SavingsAccount(10); / balance is 0
b.deposit(5000); / balance is 5000
b.withdraw(b.getBalance() / 2); / balance is 2500
b.addInterest(); / balance is 2750
R10.2
The SavingsAccount has one c
Chapter 9 Review Exercise Solutions
R9.1
The following require a cast:
c = i; / c = (C) i;
i = j; / i = (I) j;
R9.2
None of them will throw an exception.
R9.3
The following are legal:
a. e = sub;
c. sub = (Sandwich) e;
The following statement will compile
Chapter 8 Review Exercise Solutions
R8.1
class VendingMachine to display available products
class Product to represent the each product in the machine
class Coin to represent coin values such as quarters, nickels, etc.
R8.2
class PayCheck to represent a p
Chapter 7 Review Exercise Solutions
R7.1
An index is an integer value which represents a position in an array or array list.
The bounds are the lowest and highest legal index value; that is, 0 and one less than the
length of the array/size of the array li
Chapter 6 Review Exercise Solutions
R6.1
Java supports while, for, and do loops. while loops are used when the loop must
continue until a certain condition is met; for loops are used when a variable runs from a
starting to an ending value with a constant
Chapter 5 Review Exercise Solutions
R5.1
- if quarters > 0 then System.out.println(quarters + " quarters");
Missing parentheses (quarters > 0 ) and illegal keyword then
- if (1 + x > Math.pow(x, Math.sqrt(2) y = y + x;
Unbalanced parentheses around condit
Chapter 3 Review Exercise Solutions
R3.1
Because if it did not exist, we could use the default constructor to create a BankAccount
and then use the deposit method to increase the balance.
BankAccount account = new BankAccount();
account.deposit(1500);
is
Chapter 2 Review Exercise Solutions
R2.1
An object contains state information. An object reference describes the location of an
object.
R2.2
An object contains state information. An object variable contains an object reference, that
is, the location of an
Chapter 1 Review Exercise Solutions
R1.1
Programs are sequences of instructions and decisions that a computer carries out to
achieve a task. Programming means designing and implementing the instructions, as
opposed to using their results.
R1.2
A household