Quiz: Trace The Buggy Code
Trace through the following statements:
double balance = 100;
double target = 200;
double rate = 0.1;
int year = 0;
while (balance >= target)
{
double interest = balance * rate;
balance = balance + interest;
year++;
System.out.println("Year %d: %8.2f", year, balance);
}
System.out.println("Target reached!");
year |
Output | balance |
|---|
Ooops, we should have initialized: rate as a double and year as an int and balance as a double