Java Tutorial For Beginner ~ Future Prediction of tuition

in programming •  7 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
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!