168k views
0 votes
write a java program that calculates the annual interest rate ( 7%) on a credit card balance of 10,000. how many years will it take for your balance to reach 20,000 or more? use a while loop to continuously calculate the interest rate and add it to the balance until 20,000 is reached. all the variables should be declared and initialized to the values provided.

1 Answer

3 votes

public class interest_rate {

public static void main(String []args) {

double balance = 10000.0;

int year=1;

while(balance<=20000) {

balance*=1.07;

System.out.println(year + ".year balance: " + (double)Math.round(balance*100)/100+"$\\");

year++;

}

System.out.println("It took " + (year-1) + " years to reach 20.000$ or more.");

}

}

User DoctorRuss
by
3.6k points