📋 콘솔 출력

출력 명령 내용
Systme.out.print(); 인수를 문자열로 콘솔 출력
Systme.out.println(); 인수를 문자열로 콘솔 출력 + 개행(줄바꿈)
Systme.out.printf(); 서식 문자 사용 출력(문자열 포매팅)
package section18;

public class Ex1801 {
    public static void main(String[] args) {
        // print(개행 안함)
        System.out.print("Java is ");
        System.out.print("nice!");
    }
}
package section18;

public class Ex1802 {
    public static void main(String[] args) {
        // print + \\n(개행)
        System.out.print("Java is\\n");
        System.out.print("nice!");

        System.out.println(); // 개행이 포함된 출력

        // println(개행)
        System.out.println("Java is");
        System.out.print("nice!");
    }
}
서식 문자 출력 형
%d 정수(10진수)
%o 정수(8진수)
%x 정수(16진수)
%f 실수
%e 지수
%g %e 또는 %f 형태로 출력
%s 문자열
%c 문자
%% Literal %(문자열로 취급)
package section18;

public class Ex1803 {
    public static void main(String[] args) {
        System.out.println(String.format("I eat %d apples.", 5));

        System.out.printf("I eat %d apples.\\n", 5);
        System.out.printf("I eat %f apples.\\n", 2.5);
        System.out.printf("I eat %.2f apples.\\n", 2.5);
        System.out.printf("I eat %s apples.\\n", "five");
        System.out.printf("I eat %s apples.\\n", 2.5);

        System.out.printf("I have completed %d%% of my Java studies.\\n", 100);
        System.out.printf("I have completed %d%% of my %s studies.\\n", 100, "Java");
        System.out.printf("I have completed %3d%% of my %s studies.\\n", 90, "Java");
        System.out.printf("I have completed %-3d%% of my %s studies.\\n", 90, "Java");
        System.out.printf("I have completed %.2f%% of my %s studies.\\n", 99.999999, "Java"); // 반올림
    }
}

📋 콘솔 입력

✅ Scanner 클래스

📋 파일 입출력

⚙️ VSCode 한글 설정

Untitled