본문 바로가기

Study/정보처리기사

JAVA Level 2

1~5. 다음 코드에 대한 출력 결과를 쓰시오.

 

1.

public class Main {
    public static void main(String[] args) {
        int num = 6;
        if (num % 2 == 0) {
            System.out.println("Even");
        } else {
            System.out.println("Odd");
        }
    }
}

 

2.

public class Main {
    public static void main(String[] args) {
        int x = 2;
        switch (x) {
            case 1: System.out.println("One"); break;
            case 2: System.out.println("Two"); break;
            case 3: System.out.println("Three"); break;
            default: System.out.println("Other");
        }
    }
}

 

3.

public class Main {
    public static void main(String[] args) {
        for (int i = 0; i < 4; i++) {
            System.out.println(i);
        }
    }
}

 

4.

public class Main {
    public static void main(String[] args) {
        int i = 2;
        while (i < 5) {
            System.out.println(i);
            i++;
        }
    }
}

 

5.

public class Main {
    public static void main(String[] args) {
        int i = 1;
        do {
            System.out.println(i);
            i++;
        } while (i <= 3);
    }
}

 


 

정답
(드래그 시 정답이 보입니다.)

1. Even
2. Two

3. 0

1

2

3


4. 2

3

4


5. 1

2

3

'Study > 정보처리기사' 카테고리의 다른 글

JAVA Level 4  (0) 2025.02.21
JAVA Level 3  (0) 2025.02.21
JAVA Level 1  (0) 2025.02.21
C언어 Level 10  (0) 2025.02.20
C언어 Level 9  (0) 2025.02.20