본문 바로가기
정보처리기사

정보처리기사 실기 JAVA 기출문제 모음 (최근 5개년)

by 셈이 2025. 4. 18.
728x90
반응형

안녕하세요. 정보처리기사 실기 시험 기출문제 중 JAVA 관련 문제들만 선별하여 정리한 자료입니다.

 

2020년 정보처리기사가 개편된 이후부터 최근 5개년 간의 기출문제를 유형별로 정리하였습니다.

 

시험을 준비하시는 분들께 도움이 되기를 바랍니다.

 

 

아래는 이 자료에 포함된 기출문제 회차 목록입니다.

  • 2024년 1회 / 2회 / 3회
  • 2023년 1회 / 2회 / 3회
  • 2022년 1회 / 2회 / 3회
  • 2021년 1회 / 2회 / 3회
  • 2020년 1회 / 2회 / 3회

 

1. 2020년 1회차 (1)

public class Good {
    public static void main(String[] args) {
        int[] a = {0, 1, 2, 3};

        for (int i = 0; i < 4; i++) {
            System.out.print(a[i] + " ");
        }
    }
}

답) 0 1 2 3

 

 

2. 2020년 2회차 (1)

class A {
    private int a;

    public A(int a) {
        this.a = a;
    }

    public void display() {
        System.out.println("a=" + a);
    }
}

class B extends A {
    public B(int a) {
        super(a);
        display(); // super.display()도 가능하지만 this.display()가 더 자연스럽다.
    }
}

public class Good {
    public static void main(String[] args) {
        B obj = new B(10);
    }
}

답) a=10

 

 

3. 2020년 2회차 (2)

 

조건 : 빈칸에 들어갈 알맞은 말을 쓰세요.

class Parent {
    public void show() {
        System.out.println("Parent");
    }
}

class Child extends Parent {
    public void show() {
        System.out.println("Child");
    }
}

public class Good {
    public static void main(String[] args) {
        Parent pa = _______ Child(); // ← 이 부분이 문제의 빈칸
        pa.show();
    }
}

답) new

 

 

4. 2020년 3회차 (1)

public class Good {
    public static void main(String[] args) {
        int i = 0;
        int sum = 0;
        
        while (i < 10) {
            i++;
            if (i % 2 == 1)
                continue;  // i가 홀수면 아래 코드 건너뛰고 다음 반복으로
            sum += i;       // i가 짝수일 때만 sum에 더함
        }

        System.out.println(sum);
    }
}

답) 30

 

 

5. 2020년 3회차 

abstract class vehicle
{
	private String name;
    abstract public String getName(String val);
    public String getName()
    {
    	return "vehicle name:" + name;
    }
	public void setName(String val)
    {
    	name = val;
    }
}

class Car extends Vehicle
{
	public Car(String val)
    {
    	setName(val);
    }
    public String getName(String val)
    {
        return "Car name : " + val;
	}
    public String getName(byte val[])
    {
        return "Car name : " + val;
	}
}

public class good 
{
	public Static void main(String[] args)
    {
        Vehicle obj = new Car("Spark");
        System.out.print(obj.getName());
    }
}

답) vehicle name:Spark

 

 

6. 2020년 4회차

class Parent {
    public int compute(int num) {
        if (num <= 1) return num;
        return compute(num - 1) + compute(num - 2);
    }
}

class Child extends Parent {
    @Override
    public int compute(int num) {
        if (num <= 1) return num;
        return compute(num - 1) + compute(num - 3);
    }
}

public class Good {
    public static void main(String[] args) {
        Parent obj = new Child();
        System.out.print(obj.compute(4));
    }
}

답) 1

 

 

7. 2020년 4회차

 

조건 : 빈칸에 들어갈 알맞은 말을 쓰세요.

public class Good {
    public static void main(String[] args) {
        int[][] a = new int[___(1)___][___(2)___];  // (1.), (2.) → 3행 5열로 수정

        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 5; j++) {
                a[i][j] = j * 3 + (i + 1);
                System.out.print(a[i][j] + " ");
            }
            System.out.println();
        }
    }
}

[출력결과]

1 4 7 10 13

2 5 8 11 14

3 6 9 12 15 

답)
(1) 3
(2) 5


8. 2020년 4회차

 

조건 : 빈칸에 들어갈 알맞은 말을 쓰세요.

class Good {
    public static void main(String[] args) {
        int[] a = new int[8];
        int i = 0;
        int n = 10;

        while (_____(1)______) {           // (1.)
            a[i++] = ______(2)_______;       // (2.)
            n /= 2;
        }

        for (i = 7; i >= 0; i--) {
            System.out.print(a[i]);
        }
    }
}

출력결과 : 00001010

 

답) 
(1) n>0 or n>= 1 or i<8 or i <=7 (넷중 아무거나 써도 정답)

(2) n%2

 

 

9. 2021년 1회차

public class Good {
    public static void main(String[] args) {
        int i, j;
        for (j = 0, i = 0; i <= 5; i++) {
            j += i;
            System.out.print(i);
            if (i == 5) {
                System.out.print("=");
                System.out.print(j);
            } else {
                System.out.print("+");
            }
        }
    }
}

답) 1+2+3+4+5=15

 

 

10. 2021년 1회차

public class Good {
    public static void main(String[] args) {
        int[][] arr = new int[][]{{45, 50, 75}, {89}};
        
        System.out.println(arr[0].length); // 3
        System.out.println(arr[1].length); // 1
        System.out.println(arr[0][0]);     // 45
        System.out.println(arr[0][1]);     // 50
        System.out.println(arr[1][0]);     // 89
    }
}

답)

3
1
45
50
89

 

 

11. 2021년 2회차

class ovr {
    int sun(int x, int y) {
        return x + y;
    }
}

class ovr1 extends ovr {
    int sun(int x, int y) {
        return x + y;  // 그냥 덧셈 유지
    }
}

class ovr2 extends ovr1 {
    int sun(int x, int y) {
        return x - y + super.sun(x, y);  // → 3 - 2 + (3 + 2) = 1 + 5 = 6
    }
}

public class over1 {
    public static void main(String[] args) {
        ovr a1 = new ovr1();       // 3 + 2 = 5
        ovr a2 = new ovr2();       // 3 - 2 + (3 + 2) = 6
        System.out.println(a1.sun(3, 2) + a2.sun(3, 2));  // 5 + 6 = 11 
    }
}

답) 11

 

 

12. 2021년 2회차

 

조건 : 빈칸에 들어갈 알맞은 말을 쓰시오.

public class Test {
    public static void main(String[] args) {
        System.out.print(Test.check(1));
    }

   (_____________) String check(int num) {
        return (num >= 0) ? "positive" : "negative";
    }
}

[출력결과] positive

 

답) public static

 

 

13. 2021년 3회차

public class Testco {
    public static void main(String[] args) {
        int a = 3, b = 4, c = 3, d = 5;

        if ((a == 2 | a == c) & !(c > d) & (1 == b ^ c != d)) {
            a = b + c;
            if (7 == b ^ c != a) {
                System.out.println(a);
            } else {
                System.out.println(b);
            }
        } else {
            a = c + d;
            if (7 == c ^ d != a) {
                System.out.println(a);
            } else {
                System.out.println(d);
            }
        }
    }
}

답) 7

 

 

14. 2021년 3회차

class Connection {
    private static Connection _inst = null;
    private int count = 0;

    public static Connection get() {
        if (_inst == null) {
            _inst = new Connection(); // 첫 호출 시 인스턴스 생성
        }
        return _inst;
    }

    public void count() {
        count++;
    }

    public int getCount() {
        return count;
    }
}

public class Testcon {
    public static void main(String[] args) {
        Connection conn1 = Connection.get(); // 최초 생성
        conn1.count();                       // count = 1

        Connection conn2 = Connection.get(); // 동일 인스턴스
        conn2.count();                       // count = 2

        Connection conn3 = Connection.get(); // 동일

답) 3

 

 

15. 2022년 1회차

 

조건 : 빈칸에 들어갈 알맞은 말을 쓰세요.

class Car implements Runnable {
    int a;

    public void run() {
        System.out.println("message"); 
    }
}

public class Main {
    public static void main(String args[]) {
        Thread t1 = new Thread(new _________________());  
        t1.start();
    }
}

답) Car

 

 

16. 2022년 1회차

class A {
    int a;
    int b;
}

public class Main {
    static void func1(A m) {
        m.a *= 10;  // a = a * 10
    }

    static void func2(A m) {
        m.a += m.b; // a = a + b
    }

    public static void main(String args[]) {
        A m = new A();  // 객체 생성 (a=0, b=0)

        m.a = 100;      // a = 100
        func1(m);       // a = 100 * 10 = 1000
        m.b = m.a;      // b = 1000
        func2(m);       // a = 1000 + 1000 = 2000

        System.out.printf("%d", m.a);  // 출력: 2000
    }
}

답) 2000

 

 

17.2022년 2회차

public class Conv {
    int a;

    public Conv(int a) {
        this.a = a;
    }

    int func() {
        int b = 1;
        for (int i = 1; i < a; i++) {
            b = a * i + b;
        }
        return a + b;
    }

    public static void main(String[] args) {
        Conv obj = new Conv(3);
        obj.a = 5;  // 필드 값을 5로 변경
        int b = obj.func();
        System.out.print(obj.a + b);  // 출력
    }
}

답) 61

 

 

18. 2022년 2회차

#include <stdio.h>

struct A {
    int n;
    int g;
};

int main() {
    struct A a[2];  // new A[2] → C에서는 배열 선언으로 처리
    int i;

    for (i = 0; i < 2; i++) {
        a[i].n = i;
        a[i].g = i + 1;
    }

    printf("%d\n", a[0].n + a[1].g);  // a[0].n = 0, a[1].g = 2 → 0 + 2 = 2

    return 0;
}

답) 2

 

 

19. 2022년 2회차

public static void main(String args[]) { 
    int i = 3;
    int k = 1;

    switch (i) {
        case 1: k += 1;
        case 2: k++;
        case 3: k = 0;
        case 4: k += 3;
        case 5: k -= 10;
        default: k--;
    }

    System.out.print(k);
}

답) -8

 

 

20.2022년 3회차

public class Main {
    static int[] MakeArray() {
        int[] tempArr = new int[4];

        for (int i = 0; i < tempArr.length; i++) {  // Length → length
            tempArr[i] = i;
        }

        return tempArr;
    }

    public static void main(String[] args) {
        int[] intArr;
        intArr = MakeArray();

        for (int i = 0; i < intArr.length; i++) {   // Length → length
            System.out.print(intArr[i]);
        }
    }
}

답) 0123

 

 

21.2022년 3회차

public class Exam {
    public static void main(String[] args) {

        int a = 0;
        for (int i = 1; i < 999; i++) {
            if (i % 3 == 0 && i % 2 != 0)
                a = i;
        }

        System.out.print(a);
    }
}

답) 993

 

 

22. 2023년 1회차

class Static {
    public int a = 20;     // 인스턴스 변수
    static int b = 0;      // 클래스(static) 변수
}

public class Main {
    public static void main(String[] args) {
        int a;
        a = 10;
        Static.b = a;           // Static.b = 10

        Static st = new Static();  // 객체 생성

        System.out.println(Static.b++);  // 10 출력 후 b = 11
        System.out.println(st.b);       // static 변수는 공유 → 11
        System.out.println(a);          // 10 (main 지역 변수)
        System.out.print(st.a);         // 20 (인스턴스 변수)
    }
}

답)

10
11
10
20

 

 

23. 2023년 1회차

class Parent {
    int x = 100;

    Parent() {
        this(500);        // Parent(int x) 생성자 호출
    }

    Parent(int x) {
        this.x = x;       // Parent 클래스의 x 초기화
    }

    int getX() {
        return x;         // Parent 클래스의 x 반환
    }
}

class Child extends Parent {
    int x = 4000;

    Child() {
        this(5000);       // Child(int x) 생성자 호출
    }

    Child(int x) {
        this.x = x;       // Child 클래스의 x 초기화
    }
}

public class Main {
    public static void main(String[] args) {
        Child obj = new Child();
        System.out.println(obj.getX());  // 출력: 500
    }
}

답) 500

 

 

24. 2023년 1회차

public class Sort {

    public static void swap(int[] arr, int idx1, int idx2){
        int temp = arr[idx1];
        arr[idx1] = arr[idx2];
        arr[____(1)____] = temp; // ← (1): idx2
    }

    public static void Usort(int[] array, int length){
        for (int i = 0; i < length; i++) {
            for (int j = 0; j < length - i - 1; j++) {
                if (array[j] > array[j + 1]) {
                    swap(array, j, j + 1);
                }
            }
        }
    }

    public static void main(String[] args) {
        int[] item = new int[] { 5, 3, 8, 1, 2, 7 };
        int nx = 6;
        Usort(item, ____(2)____); //

        for (int data : item) {
            System.out.print(data + " ");
        }
    }
}

답) 

(1) idx2

(2) nx

 

 

25. 2023년 1회차

abstract class Vehicle {  // (오타) abstact → abstract 로 수정

    String name;

    abstract public String getName(String val);  // 추상 메서드

    public String getName() {
        return "Vehicle name: " + name;  // 기본 name 출력용 메서드
    }
}

class Car extends Vehicle {

    public Car(String val) {
        name = super.name = val;  // name에 "Spark" 저장
    }

    @Override
    public String getName(String val) {
        return "Car name:" + val;  // 오버라이딩된 메서드
    }

    // 오버로딩 (byte 배열 버전)
    public String getName(byte[] val) {
        return "Car name:" + new String(val);  // 보기 좋게 출력
    }
}

public class Main {

    public static void main(String[] args) {
        Vehicle obj = new Car("Spark");
        System.out.println(obj.getName());  // 인자 없는 메서드 호출
    }
}

답) Vehicle name: Spark

 

 

26. 2023년 2회차

public class Problem{
    public static void main(String[] args){
 m = 4620;
 
 a = (              );
 b = (              );
 c = (              );
 d = (              );
 
 System.out.println(a); //천원짜리     4장 출력
 System.out.println(b); //오백원짜리  1개 출력
 System.out.println(c); //백원짜리     1개 출력
 System.out.println(d); //십원짜리     2개 출력
    }
}

답)

 int a = m / 1000;            // 천원짜리 개수: 4620 / 1000 = 4
 int b = (m % 1000) / 500;    // 오백원: 남은 620 / 500 = 1
 int c = (m % 500) / 100;     // 백원: 남은 120 / 100 = 1
 int d = (m % 100) / 10;      // 십원: 남은 20 / 10 = 2

 

 

27. 2023년 2회차

public class Main {
    public static void main(String[] args) {

        String str1 = "Programming";              // "" 문자열 리터럴
        String str2 = "Programming";              // 
        String str3 = new String("Programming");  // new → 새로운 객체 생성

        System.out.println(str1 == str2);         // true (동일한 리터럴, 같은 참조)
        System.out.println(str1 == str3);         // false (다른 객체 참조)
        System.out.println(str1.equals(str3));    // true (내용은 같음)
        System.out.print(str2.equals(str3));      // true (내용은 같음)
    }
}

답)

true
false
true
true

 

 

28. 2024년 1회차

class Connection {
 
    private static Connection _inst = null;
    private int count = 0;
    
    static public Connection get() {
        if(_inst == null) {
            _inst = new Connection();
            return _inst;
        }
        return _inst;
    }
    
    public void count() {
         count++; 
    }
    
    public int getCount() {
         return count; 
    }
}
 
 
public class main {  
 
    public static void main(String[] args) {
 
        Connection conn1 = Connection.get();
        conn1.count();
 
        Connection conn2 = Connection.get();
        conn2.count();
 
        Connection conn3 = Connection.get();
        conn3.count();
        
        conn1.count();
        System.out.print(conn1.getCount());
    }
 
}

답) 4

 

 

29. 2024년 1회차

class Parent {
    int x, y;

    Parent(int x, int y) {            // 1.
        this.x = x;
        this.y = y;
    }

    int getT() {                      // 2.
        return x * y;
    }
}

class Child extends Parent {         // 
    int x;

    Child(int x) {                   // 3.
        super(x + 1, x);             // → 호출됨: Parent(4, 3)
        this.x = x;
    }

    int getT(int n) {               // 4.
        return super.getT() + n;
    }
}

class Main {
    public static void main(String[] args) {  // 5.
        Parent parent = new Child(3);         // 6.
        System.out.println(parent.getT());    // 7.
    }
}

답) ⑤ → ⑥ → ③ → ① → ⑦ → ②

 

 

30. 2024년 1회차

class classOne {
    int a, b;

    public classOne(int a, int b) {
        this.a = a;
        this.b = b;
    }

    public void print() {
        System.out.println(a + b);
    }
}

class classTwo extends classOne {
    int po = 3;

    public classTwo(int i) {
        super(i, i + 1);  // 부모 생성자 호출 → classOne(i, i+1)
    }

    @Override
    public void print() {
        System.out.println(po * po);  // 3 * 3 = 9
    }
}

public class main {
    public static void main(String[] args) {
        classOne one = new classTwo(10);
        one.print();
    }
}

답) 9

 

 

31. 2024년 2회차

class Main {
    public static void main(String[] args) {
        int[] a = new int[]{1, 2, 3, 4};
        int[] b = new int[]{1, 2, 3, 4};
        int[] c = new int[]{1, 2, 3};

        check(a, b);  // → a와 b는 내용이 같지만 다른 객체
        check(a, c);  // → 내용도 다르고 객체도 다름
        check(b, c);  // → 내용 다르고 객체 다름
    }

    public static void check(int[] a, int[] b) {
        if (a == b) {
            System.out.print("O");
        } else {
            System.out.print("N");
        }
    }
}

답) NNN

 

 

32. 2024년 2회차

interface Number {
    int sum(int[] a, boolean odd); // odd가 true면 홀수 합, false면 짝수 합
}

class ODDNumber implements Number {
    public int sum(int[] a, boolean odd) {
        int result = 0;
        for (int i = 0; i < a.length; i++) {
            if ((odd && a[i] % 2 != 0) || (!odd && a[i] % 2 == 0)) {
                result += a[i];
            }
        }
        return result;
    }
}

public class Main {
    public static void main(String[] args) {
        int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
        ODDNumber OE = new ODDNumber();

        System.out.print(OE.sum(a, true) + ", " + OE.sum(a, false));
    }
}

답) 25, 20

 

 

33. 2024년 2회차

class Main {
    public static void main(String[] args) {
        String str = "abacabcd";
        boolean[] seen = new boolean[256];
        System.out.print(calculFn(str, str.length() - 1, seen));
    }

    public static String calculFn(String str, int index, boolean[] seen) {
        if (index < 0) return "";

        char c = str.charAt(index);
        String result = calculFn(str, index - 1, seen);

        if (!seen[c]) {
            seen[c] = true;
            return result + c;  // ← 현재 문자를 뒤에 붙이기
        }

        return result;
    }
}

답) dcba

 

34. 2024년 2회차

class Main {
    public static void main(String[] args) {
        String str = "ITISTESTSTRING";
        String[] result = str.split("T");
        System.out.print(result[3]);
    }
}

답) S

 

 

35. 2024년 3회차

public class Main {
    static String[] s = new String[3];

    static void func(String[] s, int size) {
        for (int i = 1; i < size; i++) {
            if (s[i - 1].equals(s[i])) {
                System.out.print("O");
            } else {
                System.out.print("N");
            }
        }
        for (String m : s) {
            System.out.print(m);
        }
    }

    public static void main(String[] args) {
        s[0] = "A";                   // 문자열 리터럴
        s[1] = "A";                   // 동일한 리터럴 → 같은 객체
        s[2] = new String("A");       // 새 객체 → 다른 주소지만 equals는 true

        func(s, 3);
    }
}

답) OOAAA

 

 

36. 2024년 3회차

public class Main {
    public static void main(String[] args) {
        Base a = new Derivate();  // 업캐스팅 (다형성)
        Derivate b = new Derivate();

        System.out.print(a.getX() + a.x + b.getX() + b.x);
    }
}

class Base {
    int x = 3;

    int getX() {
        return x * 2;
    }
}

class Derivate extends Base {
    int x = 7;

    int getX() {
        return x * 3;
    }
}

답) 52

 

 

37. 2024년 3회차

public class ExceptionHandling {
    public static void main(String[] args) {
        int sum = 0;
        try {
            func();  // NullPointerException 발생
        } catch (NullPointerException e) {
            sum = sum + 1;  // 이 블록이 실행됨
        } catch (Exception e) {
            sum = sum + 10; // 이 블록은 실행되지 않음
        } finally {
            sum = sum + 100; // 무조건 실행
        }
        System.out.print(sum);  // 결과 출력
    }

    static void func() throws Exception {
        throw new NullPointerException(); 
    }
}

답) 101

 

 

38. 2024년 3회차

class Main {

    public static class Collection<T> {
        T value;

        public Collection(T t) {
            value = t;
        }

        public void print() {
            new Printer().print(value);
        }

        class Printer {
            void print(Integer a) {
                System.out.print("A" + a);
            }

            void print(Object a) {
                System.out.print("B" + a);
            }

            void print(Number a) {
                System.out.print("C" + a);
            }
        }
    }

    public static void main(String[] args) {
        new Collection<>(0).print();
    }
}

답) B0

728x90
반응형