[英]How to add padding to left and right of a string in Java
I want to add padding to left and right of my string and print something like:我想在我的字符串的左右添加填充并打印如下内容:
| WELCOME TO THE GAME |
I am trying this:我正在尝试这个:
System.out.printf("|%15s%20s|%n",header,"");
and the output is: output 是:
|WELCOME TO THE GAME |
I have 2 questions here:我在这里有两个问题:
change it to 30, 10将其更改为 30、10
System.out.printf("|%30s%10s|%n",header,"");
it's output它是 output
| WELCOME TO THE GAME |
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.