Java Tutorial For Beginner ~ Future Prediction of tuition

in #programming7 years ago


A problem to solve

Suppose that the tuition for a university is $10,000 this year and tuition

increases 7% every year. In how many years will the tuition be doubled?

public class FutureTuition {
double tuition = 10000;
int year = 0;
while (tuition < 20000) {
tuition = tuition * 1.07;
year++;
}

        System.out.println("Tuition will be doubled in " + year + " 

years");
System.out.printf("Tuition will be $%.2f in %1d years", tuition,

year);
}
}

Brief explanations

The while loop is used to repeatedly compute the tuition for a new year. The

loop terminates when the tuition is greater than or equal to 20000


▶️ DTube
▶️ IPFS

Coin Marketplace

STEEM 0.20
TRX 0.25
JST 0.039
BTC 97542.75
ETH 3458.83
USDT 1.00
SBD 3.15