求java大神,帮忙

求java大神,帮忙求解,求大佬,那个5.31
2025-03-03 10:19:42
推荐回答(1个)
回答1:

import java.util.Formatter;
import java.util.Scanner;

public class Count {

private static double statistics(double amount, double yield) {
return amount + amount * yield / 1200;
}

public static void main(String[] args) {
System.out.print("Enter the initial deposit amount:");
Scanner scanner1 = new Scanner(System.in);
String input = scanner1.nextLine().trim();
long amount = Long.parseLong(input);
System.out.print("Enter annual percentage yield:");
Scanner scanner2 = new Scanner(System.in);
input = scanner2.nextLine().trim();
double yield = Double.parseDouble(input);
System.out.print("Enter maturity period (number of months):");
Scanner scanner3 = new Scanner(System.in);
input = scanner3.nextLine().trim();
int period = Integer.parseInt(input);
System.out.println("Month     CD Value");
double temp_amount = amount;
for (int i = 0; i < period; i++) {
temp_amount = Double.parseDouble(new Formatter().format("%.2f", statistics(temp_amount, yield)).toString());
System.out.println((i + 1) + "     " + temp_amount);
}
scanner1.close();
scanner2.close();
scanner3.close();
}

}

上图是运行结果。请参考。