假设今年某大学的学费为10000美元,学费的年增长率为5%。一年后,学费将是10500美元。编写程序,计算10年后的学费,以及从现在开始的10年后算起,4年内总学费是多少?
public class Tuition {
public static void main(String[] args) {
double s=10000;
for(int i =1;i <= 10;i++ ) {
s *=1.05;}
System.out.println("Tuition after ten years is: "+ s);
double sum = 0;
for(int i = 1;i <= 4;i++){
s *= 1.05;
sum += s;
}
System.out.println("From now on, 10 years later, the total tuition fee within 4 years is : " + sum);
}
}