previous |
start |
next
Common Error: Off-by-1 Error
- year = 0;
while (balance < targetBalance)
{
year++;
double interest = balance * rate / 100;
balance = balance + interest;
}
System.out.println("Reached target after "
+ year + " years.");
- Should year start at 0 or 1?
- Should the test be < or <=?
previous |
start |
next