我無法弄清楚如何在JAVA中將這些列對齊。我嘗試了幾種方法,但都沒有工作。它適用於其他角色,但不適用於中文。如何對齊Java中的下一行?
String line1="凍結金額";
String line2="投資中金額";
String line3="投資中金額額";
String line4="投資中金中金額";
System.out.format("%-10s %s %n",line1, "XX");
System.out.format("%-10s %s %n",line2, "XX");
System.out.format("%-10s %s %n",line3, "XX");
System.out.format("%-10s %s %n",line4, "XX");
這是預期的結果,但即使在這裏沒有正確
凍結金額 XX
投資中金額 XX
投資中金額額 XX
投資中金中金額 XX
請舉一個例子,說明你不想輸出! – tilpner
顯然對齊。這是一個10字符寬度的列,右對齊。 –