예제를 통해 배워보자.
public class Ex_JS {
public static void main(String[] args) {
int a = 7;
int b = -25;
int c = 200;
System.out.printf("%7d%n", a);
System.out.printf("%07d%n", b);
System.out.printf("%+7d%n", c);
System.out.printf("%-7d%n", c);
}
}
출력값:
7
-000025
+200
200
%와 d사이에 오는 숫자만큼 자리를 확보한다.
+는 숫자가 양수일때 숫자앞에 +를 표시하고
-는 숫자를 왼쪽으로 정렬한다.