T1047-正确答案,请拿走
<!--Markdown-->
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
double tuition = 10000;
for (int i = 0; i < n; i++) {
tuition = tuition * (1 + 0.05);
tuition = Math.ceil(tuition * 100) / 100;
}
double ntuition = tuition;
double sum = 0;
for (int i = 0; i < 4; i++) {
sum += tuition;
tuition = (tuition * (1 + 0.05));
tuition = Math.ceil(tuition * 100) / 100;
}
System.out.println("Tuition after " + n + " year: " + ( n == 1 || n == 2 ? String.format("%.2f", ntuition) : Math.ceil(ntuition * 100) / 100));
System.out.println("Tuition for 4 year: " + Math.ceil(sum * 100) / 100);
in.close();
}
}
Comments: