【发布时间】:2018-04-23 20:41:04
【问题描述】:
我想在控制台中美化我的版本。 我现在如何像在表格中一样写下整个内容? 我试过用空格来计数,但随着值的变化,这非常糟糕。你知道如何美化它们之间的问题吗?
我的代码:
private static void berechneVerbrauch(Tankbeleg[] tanken) {
System.out.print("Datum" + " KM-Stand" + " Liter" + " Preis" + " Verbrauch");
System.out.println(" ");
for (int i = 0; i < tanken.length; i++) {
System.out.print(tanken[i].datum + " " + tanken[i].kmStand + " " + tanken[i].getankteLiter + " " + tanken[i].literPreis+ " " );
System.out.println(" ");
}
}
提前谢谢你
最好的问候 迈克尔
编辑
private static void berechneVerbrauch(Tankbeleg[] tanken) {
System.out.print("Datum" + "\tKM-Stand" + "\tLiter" + "\tPreis" + "\tVerbrauch");
System.out.println(" ");
for (int i = 0; i < tanken.length; i++) {
//System.out.printf("%s %s %s %s", tanken[i].datum, tanken[i].kmStand, tanken[i].getankteLiter, tanken[i].literPreis);
System.out.print(tanken[i].datum + "\t" + tanken[i].kmStand + "\t" + tanken[i].getankteLiter + "\t" + tanken[i].literPreis+ "\t" );
System.out.println(" ");
}
}
【问题讨论】: