| %b | boolean형식으로 출력 |
| %d | 10진(decimal) 형식 출력 |
| %o | 8진(octal) 형식 출력 |
| %x or X | 16진(hexa-decimal) 형식 출력 |
| %f | 부동 소수점(floating-point) |
| %e or E | 지수(exponent) 표현식 |
| %g | %f, %e 둘중 더 간략 표현되는걸로 출력 |
| %c | 문자(character) |
| %s | 문자열(string) |
이외는 API문서-Formatter에..
System.out.printf("year:%d month:%d\n",2023,12); //year:2023 month:12
*\n, %n : 개행문자
-15를 8진,16진으로
System.out.printf("%o, %x",15,15); // 17, f
-# : 값에 진수 접두사 붙이기
System.out.printf("%#X",15); //0XF
-15를 2진수로(참고)
System.out.printf("%s",Integer.toBinaryString(15)); //1111
System.out.printf("%f",123.456789f); //123.456787
//float 정밀도 소수점포함 7자리라 123.456 이후 숫자 의미x
System.out.printf("%e",0.00000001); //1.000000e-08
//5자리로 , 왼쪽정렬, 공백0으
System.out.printf("[%5d]%n",22); //[ 22]
System.out.printf("[%-5d]",22); //[22 ]
System.out.printf("[%05d]",22); //[00022]
//부분출력 .4 = 4자리
System.out.printf("%.4s","blueprint");//blue
//%전체자리수.소수점아래f
double d= 1.23456789;
System.out.printf("%14.10f",d);//[ 1.2345678900]
//전체 14자리중 수소점 아래10자리
//앞에 빈자리는 공백, 뒤에 빈자리는 0으로 채움
'Java' 카테고리의 다른 글
| [Java] OverFlow & UnderFlow (0) | 2023.12.08 |
|---|---|
| [Java] Scanner, Math.round(), Math.random() (0) | 2023.12.08 |
| [Java] 문자,문자열 결합과 두 변수 바꾸기 (0) | 2023.12.08 |
| [Java] 타입불일치와 형변환 (0) | 2023.12.05 |
| [Java] 변수와 데이터타입과 범위 (0) | 2023.12.05 |