値の表 (月、利息、支払い、合計金額など) を出力するプロジェクトに取り組んでいます。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("");