📄 padwithspaces.java
字号:
public class PadWithSpaces
{
public static void main(String[] args)
{
final int WIDTH = 8; // this sets the size of the output field
int n, numlength;
String outstr = "";
int testNumber;
testNumber = 6; // this is the number we will output
outstr += testNumber; // convert to a string
numlength = outstr.length(); // get the number of integer digits
n = WIDTH - numlength; // determine number of spaces needed
outstr = addSpaces(n) + outstr;
System.out.println(outstr);
}
// this method creates a string with n space characters
public static String addSpaces(int n)
{
StringBuffer temp = new StringBuffer(n);
int i;
for(i = 0; i < n; i++)
temp.append(' '); // append a blank
return temp.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -