반응형
%d
데이터 형식: 10진수 byte, short, int, long
사용예제:
String temp = String.format("%d", 29);
System.out.println(temp); // 29
%숫자d
데이터 형식: 10진수 byte, short, int, long
사용예제:
String temp = String.format("%5d", 29);
System.out.println(temp); // _ _ _29
%o
데이터 형식: 8진수 byte, short, int, long
사용예제:
String temp = String.format("%o", 10);
System.out.println(temp); // 12
%x
데이터 형식: 16진수 byte, short, int, long
사용예제:
String temp = String.format("%x", 10);
System.out.println(temp); // a
%f
데이터 형식: 실수 float, double
사용예제:
String temp = String.format("%f", 123.4567);
System.out.println(temp); // 123.456700
%.숫자f
데이터 형식: 실수 float, double
사용예제:
String temp = String.format("%.2f", 123.4567);
System.out.println(temp); // 123.46
%e
데이터 형식: e 표기법에 의한 실수
사용예제:
String temp = String.format("%e", 874.9163);
System.out.println(temp); // 8.749163e+02
%s
데이터 형식: 문자열(String) 데이터
사용예제:
String temp = String.format("%s", System.lineSeparator());
System.out.println(temp); // 줄바꿈
%c
데이터 형식: 문자(Character) 데이터
사용예제:
String temp = String.format("%c", 'y');
System.out.println(temp); // y
반응형
'old > Programming' 카테고리의 다른 글
논리 게이트 진리표&정의 (0) | 2023.10.25 |
---|---|
네덜란드 국기(Dutch National Flag) 알고리즘이란 (0) | 2023.08.19 |
재귀 함수 짜는 법 (0) | 2023.08.18 |
파이썬의 연산자 정리 (0) | 2023.08.10 |
최소 공통 조상, LCA(Lowest Common Ancestor)이란 (0) | 2023.08.06 |