JAVA/02_기본 구문
printf
Y_____527
2021. 1. 10. 23:10
package ex01.Printf;
public class MainEntry {
public static void main(String[] args) {
System.out.println("yyr");
System.out.printf("%c %s %d %f", 'A', "yerin", 3000, 12.34); //%f: 소수점 default로 6자리 출력
System.out.println();
System.out.printf("%c %s %d %10.1f \n", 'A', "yerin", 3000, 12.34); //%M.Nf
System.out.printf("\n\n%10.1f\n", 12.34);
//%10.1f는 공간을 10자리수로 만들고 그 안에서 해당 수를 넣어 소수점 1자리까지 나타냄
System.out.printf("%3.1f\n", 12345.3456789); //소수점위의 정수들은 정해진 공간크기와 상관없이 모두 출력됨
System.out.printf("%.2f", 12345.3456789);
}
}
//제어문자: \문자 -\n, \t, \a....
//printf() - 서식에 맞춰서 출력: %문자 - %c, %s, %d, %i, %f,...
yyr
A yerin 3000 12.340000 ->%f: 소수점 default로 6자리 출력
A yerin 3000 12.3 ->%10.1f는 공간을 10자리수로 만들고 그 안에서 해당 수를 넣어 소수점 1자리까지 나타냄
12.3 ->%10.1f는 12.34를 10칸의 공간에서 소수점 첫째자리 수까지 나타냄
12345.3 ->소수점위의 정수들은 정해진 공간크기와 상관없이 모두 출력됨
12345.35
->제어문자: \문자 -\n, \t, \a....
->printf() - 서식에 맞춰서 출력: %문자 - %c, %s, %d, %i, %f,...