Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 贷款分期付款计划,计划日期为爪哇语_Java_Date - Fatal编程技术网

Java 贷款分期付款计划,计划日期为爪哇语

Java 贷款分期付款计划,计划日期为爪哇语,java,date,Java,Date,我试图在我的贷款计划中包含计划日期,但日期错误,因为它们跳过了几个月: public static void printAmortizationSchedule(double principal, double annualInterestRate, int numYears) { double interestPaid, principalPaid, newBalance; double monthlyInterestRate, monthlyPayment;

我试图在我的贷款计划中包含计划日期,但日期错误,因为它们跳过了几个月:

 public static void printAmortizationSchedule(double principal, double annualInterestRate, int numYears) {
        double interestPaid, principalPaid, newBalance;
        double monthlyInterestRate, monthlyPayment;
        int month;
        int numMonths = numYears * 12;

        // Output monthly payment and total payment
        monthlyInterestRate = annualInterestRate / 12;
        monthlyPayment = monthlyPayment(principal, monthlyInterestRate, numYears);
        System.out.format("Monthly Payment: %8.2f%n", monthlyPayment);
        System.out.format("Total Payment:   %8.2f%n", monthlyPayment * numYears * 12);

        // Print the table header
        printTableHeader();
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());
        for (month = 1; month <= numMonths; month++) {
            // Compute amount paid and new balance for each payment period
            interestPaid = principal * (monthlyInterestRate / 100);
            principalPaid = monthlyPayment - interestPaid;
            newBalance = principal - principalPaid;
            cal.add(Calendar.MONTH, month);
            SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-YYYY", Locale.getDefault());
            String dddate = sdf.format(cal.getTime());
            // Output the data item
            printScheduleItem(month, dddate, interestPaid, principalPaid, newBalance);

            // Update the balance
            principal = newBalance;
        }
    }
我敢肯定,问题在于将月份添加到日期中,我如何解决这个问题?

您的错误在这里:

cal.add(Calendar.MONTH, month);
应该是:

cal.add(Calendar.MONTH, 1);
cal.add(日历月、月份)可能应该是
cal.add(日历月,1)
如果您需要的是日期(没有时间),您可能应该使用而不是
日历
cal.add(Calendar.MONTH, 1);