Imagine, you open an account with $1200 deposit at interest rate
of 8% per year.
Every year you collect the interest and withdraw $100.
Display how many years it takes until your balance goes below
$100.
public static void main(String[] args)
{
while
......
}
Code is Given Below:
==========================
public class IntrestCalc {
public static void main(String[] args) {
//declaring variable to hold
balance and year
double balance=1200;
int year=0;
//loop will run until balance is
greater than 100
while(balance>=100) {
//incrementing
year
year++;
//adding intrest
to balance
balance =
balance +balance*0.08;
balance=balance-100;
}
//display result
System.out.println("Years =
"+year);
}
}
Output:
=============
Code Snapshot:
=====================
Get Answers For Free
Most questions answered within 1 hours.