System.out.print("Hello!");
System.out.print("Hello!");
result
Hello!Hello!
System.out.println("Hello!");
System.out.println("Hello!");
result
Hello!
Hello!
지시자 | 설명 |
---|---|
%c | 문자(character) 형식으로 출력 |
%s | 문자열(string) 형식으로 출력 |
%b | boolean 형식으로 출력 |
%d | 10진수(decimal) 형식으로 출력 |
%o | 8진수(octal) 형식으로 출력 |
%x | 16진수(hexadecimal) 형식으로 출력 |
%f | 부동소수점(floating point) 형식으로 출력 |
%e | 지수(exponent) 표현식의 형식으로 출력 |
%n | 줄바꿈 |
System.out.printf("%d", 10); // 10
System.out.println();
System.out.printf("%o%n", 10); // 12
System.out.printf("%x", 10); // a
result
10
12
a
String name = "John";
int age = 30;
System.out.printf("My name is %s. I'm %d years old.%n", name, age);
System.out.printf("My name is %s. I'm %d years old.", "", age);
result
My name is John. I'm 30 years old.
My name is . I'm 30 years old.