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

정보처리산업기사 실기 Java 기출문제 정리

by Hwangminseo 2026. 4. 9.

문제1 (22년 1회 19번)

문제1 : 결과 값을 구하시오

소스 :

public class Test {
    public static void main(String args[]) {
        int a = 0, ss = 0;
        while (true) {
            if (ss > 100) break;
            ++a;
            ss += a;
        }
        System.out.print(a + ss);
    }
}
정답 확인
답 : 119

해설 : a를 1씩 증가시키면서 ss에 누적합을 저장한다. ss가 100을 초과하는 순간 반복을 종료한다. 1부터 14까지의 합은 105이므로 종료 시점의 a=14, ss=105이고 출력값은 a+ss=119이다.

문제2 (22년 1회 20번)

문제2 : 결과 값을 구하시오

소스 :

public class Test {
    public static void main(String args[]) {
        int x = 1, T_x = 0, t_x = 0;
        T_x = (x >= 0) ? x : -x;
        if (x >= 0)
            t_x = x;
        else
            t_x = -x;
        System.out.println(T_x + " " + t_x);
    }
}
정답 확인
답 : 1 1

해설 : 삼항 연산자와 if-else 모두 x의 절댓값을 구하는 코드다. x가 1이므로 T_x와 t_x 모두 1이 저장되고 1 1이 출력된다.

문제3 (22년 2회 10번)

문제3 : 결과 값을 구하시오

소스 :

class Test {
    public static void main(String args[]) {
        int i = 17;
        i += 1;
        i -= 2;
        i *= 3;
        i /= 4;
        i %= 5;
        System.out.print(i);
    }
}
정답 확인
답 : 2

해설 : 순서대로 계산하면 17 → 18 → 16 → 48 → 12 → 2가 된다. 마지막 나머지 연산 결과가 출력된다.

문제4 (22년 2회 16번)

문제4 : 결과 값을 구하시오

소스 :

class Test {
    public static void main(String args[]) {
        int a = 26;
        int b = 91;
        int g = 0;
        int c = a < b ? a : b;
        for (int i = 1; i < c; i++) {
            if (a % i == 0 && b % i == 0)
                g = i;
        }
        System.out.print(g);
    }
}
정답 확인
답 : 13

해설 : a와 b 중 작은 값인 26 전까지 공약수를 찾고, 공약수를 만날 때마다 g에 저장한다. 마지막으로 저장되는 가장 큰 공약수는 13이므로 출력값은 13이다.

문제5 (22년 3회 3번)

문제5 : 결과 값을 구하시오

소스 :

class Main {
    public static void main(String args[]) {
        int[] a = new int[8];
        int i = 0;
        int n = 11;
        while (n > 0) {
            a[i++] = n % 2;
            n /= 2;
        }
        for (i = 7; i >= 0; i--)
            System.out.printf("%d", a[i]);
    }
}
정답 확인
답 : 00001011

해설 : 11을 2진수로 바꾸는 과정이다. n % 2 결과를 배열에 역순으로 저장한 뒤 뒤에서부터 출력하므로 8비트 형태의 00001011이 된다.

문제6 (22년 3회 15번)

문제6 : 결과 값을 구하시오

소스 :

class Main {
    public static void main(String args[]) {
        int a[][] = new int[3][3];
        init(a);
        data(a);
        prnt(a);
    }

static void init(int a[][]) {
    for (int i = 0; i &lt; 3; i++)
        for (int j = 0; j &lt; 3; j++)
            a[i][j] = 0;
}

static void data(int a[][]) {
    int v = 1;
    for (int i = 0; i &lt; 3; i++)
        for (int j = i; j &lt; 3; j++)
            a[i][j] = v++;
}

static void prnt(int a[][]) {
    for (int i = 0; i &lt; 3; i++) {
        for (int j = 0; j &lt; 3; j++) {
            if (a[i][j] == 0)
                System.out.printf(&quot; &quot;);
            else
                System.out.printf(&quot;%d&quot;, a[i][j]);
        }
        System.out.println();
    }
}

}

정답 확인
답 : 123
45
6

해설 : 초기화 후 data()에서 주대각선 위쪽 영역만 1부터 차례대로 채운다. 배열 상태는 [1 2 3], [0 4 5], [0 0 6]이 되고, 0은 공백으로 출력하므로 최종 결과는 세 줄로 123, 45, 6이 된다.

문제7 (23년 1회 12번)

문제7 : 결과 값을 구하시오

소스 :

public class Main {
    public static void main(String[] args) {
        int x = 1;
        System.out.println(!(x > 0));
        System.out.println((x != 0) || (x > 0));
        System.out.println(x << 2);
        System.out.println(x & 2);
        System.out.println(x %= 3);
    }
}
정답 확인
답 : false
true
4
0
1

해설 : x는 1이다. !(x > 0)은 false, (x != 0) || (x > 0)은 true다. x << 2는 1을 두 비트 왼쪽 이동하므로 4, x & 2는 1과 2의 비트 AND이므로 0이다. 마지막 x %= 3은 1 % 3 결과인 1을 다시 x에 저장하고 출력한다.

문제8 (23년 2회 15번)

문제8 : 결과 값을 구하시오

소스 :

class Main {
    public static void main(String[] args) {
        int[] a = {4, 7, 1, 2};
        for (int i = 0; i < 3; i++) {
            for (int j = i + 1; j < 4; j++) {
                if (a[i] > a[j]) {
                    int temp = a[j];
                    a[j] = a[i];
                    a[i] = temp;
                }
            }
        }
        for (int i = 0; i < 4; i++) {
            System.out.print(a[i] + "a");
        }
    }
}
정답 확인
답 : 1a2a4a7a

해설 : 이중 반복문으로 오름차순 정렬이 수행된다. 정렬 후 배열은 [1, 2, 4, 7]이 되고 각 원소 뒤에 문자 a를 붙여 연속 출력하므로 1a2a4a7a가 된다.

문제9 (23년 3회 10번)

문제9 : 결과 값을 구하시오

소스 :

class Berry {
    String Str;
    void meth() {
        func();
    }
    void func() {
        System.out.println(Str);
    }
}

class Apple extends Berry {
String Str;
void func() {
Str = "Apple";
super.Str = "Berry";
super.func();
System.out.println(Str);
}
}

public class Main {
public static void main(String[] args) {
Berry A = new Apple();
A.meth();
}
}

정답 확인
답 : Berry
Apple

해설 : 참조 변수 타입은 Berry지만 실제 객체는 Apple이므로 동적 바인딩에 의해 func()는 Apple의 메서드가 호출된다. Apple의 func()에서 자신의 Str에는 Apple, 부모의 Str에는 Berry를 넣고 super.func()를 호출해 부모 Str을 먼저 출력한 뒤 자신의 Str을 출력한다.

문제10 (23년 3회 15번)

문제10 : 결과 값을 구하시오

소스 :

public class Main {
    static int a = 0;

static int func(int t) {
    a = a + t;
    return a;
}

public static void main(String[] args) {
    for (int i = 0; i &lt; 5; i++) {
        func(i);
    }
    System.out.print(a);
}

}

정답 확인
답 : 10

해설 : 반복문에서 i가 0, 1, 2, 3, 4일 때 func(i)가 호출된다. 정적 변수 a에 차례대로 더해지므로 최종 합은 0+1+2+3+4=10이다.

문제11 (23년 3회 17번)

문제11 : 결과 값을 구하시오

소스 :

class A {
    int f(int a, int b) {
        return a + b;
    }
}

public class Main {
public static void main(String[] args) {
A a = new A();
System.out.print(a.f(25, 25));
}
}

정답 확인
답 : 50

해설 : 객체 a를 생성한 뒤 메서드 f(25, 25)를 호출한다. 두 값을 더한 50이 반환되어 그대로 출력된다.

문제12 (24년 1회 4번)

문제12 : 결과 값을 구하시오

소스 :

public class Test {
    public static void main(String[] args) {
        int a[] = {1, 2, 3, 4, 5, 6};
        int sum = 0;
        for (int i : a) {
            sum += i;
        }
        System.out.print(sum);
    }
}
정답 확인
답 : 21

해설 : 향상된 for문으로 배열의 모든 원소를 sum에 더한다. 1부터 6까지의 합은 21이므로 21이 출력된다.

문제13 (24년 1회 13번)

문제13 : 빈칸에 들어갈 값을 구하시오

소스 :

public class Test {
    public static void main(String[] args) {
        int totalcnt = 10, totalleg = 26;
        int duckcnt, pigcnt;

    for (duckcnt = 1; duckcnt &lt; totalcnt; duckcnt++) {
        pigcnt = totalcnt - (가);
        if ((2 * duckcnt) + (4 * (나)) == totalleg) {
            System.out.printf(&quot;%d %d&quot;, duckcnt, pigcnt);
            break;
        }
    }
}

}

정답 확인
답 : (가) duckcnt
(나) pigcnt

해설 : 오리 수와 돼지 수의 합이 전체 마리 수 10이 되어야 하므로 pigcnt = totalcnt - duckcnt가 되어야 한다. 다리 수 조건도 (2 * duckcnt) + (4 * pigcnt) == totalleg 형태여야 맞다. 따라서 (가)는 duckcnt, (나)는 pigcnt다.

문제14 (24년 2회 4번)

문제14 : 결과 값을 구하시오

소스 :

public class Test {
    int A(int a, int b) {
        System.out.print(a + b);
        return a * b;
    }

public static void main(String[] args) {
    Test a = new Test();
    System.out.print(a.A(5, 5));
}

}

정답 확인
답 : 1025

해설 : 메서드 A(5, 5)가 먼저 호출되면서 내부에서 a+b인 10을 먼저 출력한다. 그 뒤 반환값 a*b인 25가 바깥 System.out.print()에 의해 이어서 출력되므로 최종 결과는 1025다.

문제15 (24년 3회 7번)

문제15 : 결과 값을 구하시오

소스 :

public class Main {
    public static void main(String[] args) {
        int i = 17;
        i += 1;
        i -= 2;
        i *= 3;
        i /= 4;
        i %= 5;
        System.out.print(i);
    }
}
정답 확인
답 : 2

해설 : 22년 2회 10번과 같은 문제다. 연산 순서대로 17 → 18 → 16 → 48 → 12 → 2가 되어 2를 출력한다.

문제16 (24년 3회 18번)

문제16 : 결과 값을 구하시오

소스 :

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 class Main {
public static void main(String[] args) {
new Collection<>(0).print();
}

public static class Collection&lt;T&gt; {
    T value;

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

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

}

정답 확인
답 : B0

해설 : new Collection<>(0)에서 0은 Integer처럼 보이지만, Collection 내부의 value 타입은 컴파일 시점에 제네릭 타입 변수 T다. print(value) 호출 시 오버로딩 해석은 구체적인 Integer나 Number가 아니라 최종적으로 안전한 Object 메서드로 결정되므로 B0이 출력된다.