We would like to use while loop to predict the future tuition.
Suppose that the tuition for a university is $10,000 this year.
Tuition increases 7% every year.
In how many years will the tuition be doubled?
public class Main { public static void main(String[] args) { double tuition = 10000; // Year 0 int year = 0; //your code here System.out.println("Tuition will be doubled in " + year + " years"); System.out.printf("Tuition will be $%.2f in %1d years", tuition, year); }/*from ww w .ja v a 2s . c om*/ }
public class Main { public static void main(String[] args) { double tuition = 10000; // Year 0 int year = 0; while (tuition < 20000) {// loop tuition = tuition * 1.07;// next year's tuition year++; } System.out.println("Tuition will be doubled in " + year + " years"); System.out.printf("Tuition will be $%.2f in %1d years", tuition, year); } }