我正在开发一个输出值表(月、利息、付款、总金额等)的项目。我在 NetBeans 中将值打印到控制台的列均匀地隔开并正常运行,但我在其上方还有一个打印行以显示标题,这与其余列不匹配。如果这没有任何意义,我附上了我正在使用的代码。
System.out.println("Month \t\t Start Balance \t Interest \t\t Principal \t Payment \t End Balance");
while (true) {
i++;
compCost = round(compCost);
System.out.print(i + "\t \t");//month
System.out.print(patternFormatter.format(compCost) + " \t ");//original balance
double interest = (rate / 12) * compCost;
interest = round(interest);
System.out.print(patternFormatter.format(interest) + " \t \t");//interest
sum = sum + interest;
compCost = compCost + interest;//add interest
payment = round(payment);
if (compCost > payment) {//check if payment is bigger than the cost left
compCost = compCost - payment;
double principal = payment - interest;
principal = round(principal);
System.out.print(patternFormatter.format(principal) + "\t \t");//principal
System.out.print(patternFormatter.format(payment) + "\t \t");//payment
} else {
System.out.print(patternFormatter.format(compCost - interest) + "\t \t");//principal
System.out.print(patternFormatter.format(compCost) + "\t \t");//payment
compCost = 0;
}
compCost = round(compCost);
System.out.print(patternFormatter.format(compCost));
System.out.println("");