为了能够更清晰整齐地看到输出结果,我们可以去控制输出的格式。
读入三个整数,按每个整数占 88 个字符的宽度,右对齐输出它们。
输入格式
只有一行,包含三个int范围内的整数,整数之间以一个空格分开。
输出格式
只有一行,按照格式要求依次输出三个整数,之间以一个空格分开。
样例输入
123456789 0 -1
样例输出
123456789 0 -1
这道题,我的理解是,整数长度大于8了就不用管,小于8左边添加空格补到八,每个数值中间用一个空格分开
代码实现
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String next = sc.nextLine();
String[] split = next.split(" ");
for(int i = 0; i < 3; i++){
String str = split[i];
if(str.length() < 8) {
String str1 = str;
for(int j = 0; j < 8 - str.length(); j ++){
str1 = " " + str1;
}
str = str1;
}
System.out.print(str + " ");
}
}
}