MT1016-宽度对齐
输出455、-123、987654,宽度为5,分别左对齐和右对齐
import java.util.Scanner;
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println(String.format("%-5d %5d",455,455));
System.out.println(String.format("%-5d %5d",-123,-123));
System.out.println(String.format("%-5d %5d",987654,987654));
input.close();
}
}
MT1017-左右对齐
输出3.1415926、22.3456,宽度为14,精度为6,分别左对齐和右对齐。
import java.util.Scanner;
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println(String.format("-14.6f 14.6f",3.1415926,3.1415926));
System.out.println(String.format("-14.6f 14.6f",22.3456,22.3456));
input.close();
}
}