별의 공부 블로그 🧑🏻‍💻
728x90
728x170

프로그래밍 기출 문제 정리 (2017년~2022년)

  • 정보처리기사 실기 기출 문제 중에서 프로그래밍(C, Java, Python)과 관련된 문제를 정리해 본다.
  • 이 문제들은 복원을 한 것으로, 실제 출제된 문제와 다를 수 있다.

 

2017년 1회

문제 1

Q. 다음 Java 언어로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. 

public class Test001 {
    public static void main(String[] args) {
        int[] a = {3, 4, 10, 2, 5};
        int temp;
        for (int i = 0; i <= 3; i++) {
            for (int j = i + 1; j <= 4; j++) {
                if (a[i] < a[j]) {
                    temp = a[i];
                    a[i] = a[j];
                    a[j] = temp;
                }
            }
        }
        for (int i = 0; i < 5; i++) {
            System.out.println(a[i]);
        }
    }
}

 

더보기

10

5

4

3

2

 

문제 2

Q. 다음 C 언어로 구현된 프로그램에서 괄호 (1)에 해당하는 가장 적합한 변수(Variable)나 조건식을 C 언어 코드 형식으로 쓰시오.

#include <stdio.h>
main() {
    int num[10];
    int min = 9999;
    int i;
    for (i = 0; i < 10; i++) {
        scanf("%d", &num[i]);
    }

    for (i = 0; i < 10; i++) {
        if (min > ( (  1  ) )) {
            min = num[i];
        }
    }
    print("가장 작은 값은 %d이다.", min);
}

 

더보기

num[i]

 

 

2017년 2회

문제 1

Q. 다음 C 언어로 구현된 100을 넘지 않는 소수와 개수를 구하는 프로그램에서 괄호 (1)에 해당하는 가장 적합한 변수(Variable)나 조건식을 C 언어 코드 형식으로 쓰시오.

#include <stdio.h>
int isprime(int number) {
    int i;
    for (i = 2; i < number; i++) {
        if ( (  1  ) ) 
            return 0;
    }
    return 1;
}

int main() {
    int number = 100, cnt = 0, i;
    for (i = 2; i < number; i++) {
        cnt = cnt + isprime(i);
    }
    printf("%d를 넘지 않는 소수는 %d개입니다.\n", number, cnt);
    return 0;
}

 

더보기

number % i == 0

 

문제 2

Q. 다음 Java 언어로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오.

public class Test001 {
    public static void main(String[] args) {
        int a = 0, sum = 0;
        while (a < 10)
        {
            a++;
            if (a % 2 == 1) {
                continue;
            }
            sum += a;
        }
        System.out.println(sum);
    }
}

 

 

 

2017년 3회

문제 1

Q. 다음 C 언어로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오.

#include <stdio.h>
int res10() {
    return 4;
}

int res30() {
    return 30 + res10();
}

int res200() {
    return 200 + res30();
}

int main() {
    int result;
    result = res200();
    printf("%d\n", result);
}

 

 

문제 2

Q. 다음은 배열에 저장된 5개의 자료 중 가장 큰 값과 가장 작은 값을 찾아 출력하는 프로그램을 Java 언어로 구현한 것이다. 프로그램을 분석하여 괄호에 해당하는 답안을 <답란>에 쓰시오.

public class Test02 {
    public static void main(String[] args) {
        int a[] = {10, 30, 50, 70, 90};
        int i, max, min;
        max = a[0];
        min = a[0];
        for (i = 0; i < 5; i++) {
            if ( (    ) > max) {
                max = a[i];
            }
            if ( (    ) < min) {
                min = a[i];
            }
        }
        System.out.printf("%d\n", max);
        System.out.printf("%d\n", min);
    }
}

 

더보기

a[i]

 

문제 3

Q. 다음 C 언어로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오.

#include <stdio.h>
int power(int data, int exp) {
    int i, result = 1;
    for (i = 0; i < exp; i++) {
        result = result * data;
    }
    return result;
}

int main() {
    printf("%d\n", power(2, 10));
    return 0;
}

 

더보기

1024

 

 

2018년 1회

문제 1

Q. 다음 C 언어의 <출력>과 <코드>를 보고 괄호 (1), (2), (3), (4)에 적용될 수 있는 가장 적합한 답을 쓰시오.

 

<출력>

statck's status
value = 40
value = 30
value = 20

 

<코드>

#include <stdio.h>
#define MAX_STACK_SIZE 10

int stack[MAX_STACK_SIZE];
int top = -1;

void push(int item) 
{
    if (top >= (  1  )) 
    {
        printf("stack is full\n");
    }
    stack[++top] = (  2  );
}

int pop() 
{
    if (top == (  3  ))
    {
        printf("stack is empty\n");
    }
    return stack[(  4  )];
}

int isempty()
{
    if (top == (  3  ))
    {
        return 1; 
    }
    else 
    {
        return 0;
    }
}

int isfull()
{
    if (top >= (  1  )) 
    {
        return 1;
    }
    else 
    {
        return 0;
    }
}

int main() 
{
    int e;
    push(20); push(30); push(40);
    printf("stack's status\n");
    while (!isempty())
    {
        e = pop();
        printf("value = %d\n", e);
    }
}

 

더보기

① MAX_STACK_SIZE - 1 또는 9

② item

③ -1

④ top--

 

문제 2

Q. 다음 Java 언어의 <처리 조건>과 <코드>를 보고 괄호 (1), (2)에 적용될 수 있는 가장 적합한 답을 쓰시오.

 

<처리 조건>

  • 배열에는 95, 75, 85, 100, 50이 차례대로 저장된다.
  • 배열에 저장된 값을 오름차순으로 정렬하여 출력한다.

 

<코드>

public class Test1 {
    public static void main(String[] args) {
        int E[] = { (  2  ) };
        int i = 0;
        int Temp = 0;

        do
        {
            int j = i;
            do
            {
                int j = i;
                do{
                    if (E(i) > (  2  ))
                    {
                        Temp = E[i];
                        E[i] = E[j];
                        E[j] = Temp;
                    }
                    j++;
                } while (j < 5);
                i++;
            } while (i < 4);
        }
        for (int a = 0; a < 5; a++)
        {
            System.out.printf(E[a] + "\t");
        }
        System.out.println();
    }
}

 

더보기

① 95, 75, 85, 100, 50

② E[j]

 

 

2018년 2회

문제 1

Q. 다음은 5개의 정수를 입력 받아 그 중 홀수의 개수를 구하여 출력하는 알고리즘을 C 언어로 구현한 <코드>이다. 프로그램을 분석하여 괄호 (1)에 가장 적합한 답을 쓰시오.

#include <stdio.h>

main() {
    int i, a[5], cnt = 0;

    for (i = 0; i < 5; i++) {
        scanf("%d", &a[i]);
    }

    for (i = 0; i < 5; i++) {
        if (a[i] % 2 (  1  ) 0) {
            cnt = cnt + 1;
        }
    }

    printf("홀수의 개수 : %d개", cnt);
}

 

더보기

!= 또는 >

 

문제 2

Q. 다음 Java 언어로 <출력>과 <코드>를 보고 괄호 (1), (2)에 가장 적합한 답을 쓰시오.

 

<출력>

0 1 2 3 4
1 2 3 4 5
2 3 4 5 6

 

<코드>

public class Problem {
    public static void main(String[] args) {
        int[][] a = new int[(  1  )][(  2  )];
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 5; j++) {
                a[i][j] = i + j;
                System.out.println("%d ", a[i][j]);
            }
            System.out.println();
        }
    }
}

 

더보기

① 3

② 5

 

문제 3

Q. 다음 C 언어로 <출력>과 <코드>를 보고 괄호 (1)에 가장 적합한 답을 쓰시오.

 

<출력>

1의 약수 : 1
2의 약수 : 1 2
3의 약수 : 1 3
4의 약수 : 1 2 4
5의 약수 : 1 5

 

<코드>

#include <stdio.h>

main() {
    int i, j;
    for (i = 1; i <= 5; i++) {
        printf("%d의 약수 : ", i);
        for (j = 1; j <= 5; j++) {
            if ( (  1  )) {
                printf("%d ", j);
            }
        }
        printf("\n");
    }
    return 0;
}

 

더보기

i % j == 0

 

 

2018년 3회

문제 1

Q. 다음은 피보나치 수열의 합계를 구하는 프로그램을 Java 언어로 구현한 것이다. 프로그램을 분석하여 그 실행 결과를 쓰시오.

public class Problem {
    public static void main(String[] args) {
        int a, b, c, sum;
        a = b = 1;
        sum = a + b;

        for (int i = 3; i <= 5; i++) {
            c = a + b;
            sum += c;
            a = b;
            b = c;
        }
        System.out.println(sum);
    }
}

 

 

문제 2

Q. 다음은 6면 주사위를 100번 굴려서 나온 각 면의 수를 배열에 저장하여 출력하는 알고리즘을 C 언어로 구현한 <코드>이다. 프로그램을 분석하여 괄호 (1), (2)에 가장 적합한 답을 쓰시오.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

main() {
    int hist[6] = { 0, };
    int n, i = 0;
    srand(time(NULL));

    do {
        i++;
        n = rand() % 6 + 1;
        hist[(  1  )] += 1;
    } while (i < 100);

    for (i = 0; i < 6; i++) {
        printf("[%d] = %d\n", i + 1, (  2  ));
    }
}

 

더보기

① n - 1

② hist[i]

 

문제 3

Q. 다음은 연결 리스트를 활용하여 스택 구조를 C 언어로 구현한 것이다. <출력>과 <코드>를 보고 괄호 (1), (2)에 가장 적합한 답을 쓰시오.

 

<출력>

30
20
10

 

<코드>

#include <stdio.h>
#include <stdlib.h>

struct NODE {
    int data;
    struct NODE *Next;
};

struct NODE *head;

void Push(int data) {
    struct NODE *end = malloc(sizeof(struct NODE));
    end->(  1  ) = head->(  1  );
    end->data = data;
    head->(  1  ) = end;
}

int Pop() {
    int a;

    struct NODE *del = head->(  1  );
    head->(  1  ) = del->(  1  );
    a = del->data;
    free(del);
    return a;
}

main() {
    int r;

    head = malloc(sizeof(struct NODE));
    head->(  1  ) = NULL;

    Push(10);
    Push(20);
    Push(30);

    r = (  2  );
    printf("%d\n", r);
    r = (  2  );
    printf("%d\n", r);
    r = (  2  );
    printf("%d\n", r);
}

 

더보기

① Next

② Pop()

 

728x90

 

2019년 1회

문제 1

Q. 다음 Java 언어로 구현한 프로그램을 분석하여 그 실행 결과를 쓰시오.

class SuperObject {
    public void paint() {
        draw();
    }

    public void draw() {
        draw();
        System.out.println("Super Object");
    }
}

class SubObject extends SuperObject {
    public void paint() {
        super.draw();
    }

    public void draw() {
        System.out.println("Sub Object");
    }
}

public class Test {
    public static void main(String[] args) {
        SuperObject a = new SubObject;
        a.paint();
    }
}

 

더보기
Sub Object
Super Object

 

문제 2

Q. 다음 Java 언어로 구현한 프로그램을 분석하여 그 실행 결과를 쓰시오.

public class Test {
    public static void main(String[] args) {
        int i, sum = 0;
        for (i = 1; i <= 110; i++) {
            if (i % 4 == 0) {
                sum = sum + 1;
            }
        }
        System.out.println("%d", sum);
    }
}

 

 

문제 3

Q. 다음 C 언어로 구현된 프로그램을 분석하여 괄호 (1), (2)에 가장 적합한 답을 쓰시오.

 

예) 1234567을 입력받으면 결과는 1+2+3+4+5+6+7 = 28 출력

 

#include <stdio.h>

main() {
    int input, num = 0;
    scanf("%d", &input);
    while (1) {
        if ( (  1  ) == 0) {
            break;
        }
        sum = sum + input % 10;
        input = input / (  2  );
    }
    printf("%d\n", sum);
}

 

더보기

① input

② 10

 

 

2019년 2회

문제 1

Q. 다음 Java 언어로 구현한 프로그램을 분석하여 그 실행 결과를 쓰시오.

public class Test {
    public static void main(String[] args) {
        int numAry[] = new int[5];
        int result = 0;

        for (int i = 0; i < 5; i++) {
            numAry[i] = i + 1;
        }

        for (int i : numAry) {
            result += i;
        }

        System.out.printf("%d", result);
    }
}

 

 

문제 2

Q. 다음 Java 언어로 구현한 프로그램을 분석하여 그 실행 결과를 쓰시오.

public class Test {
    public static int[] arr(int[] a) {
        int i, j, sw, temp, n = 5;
        if (a[0] == 0 || a[0] < 1) {
            return a;
        }

        for (i = 0; i < n - 1; i++) {
            sw = i;
            for (j = i + 1; j < n; j++) {
                if (a[j] > a[sw]) {
                    sw = j;
                }
            }
            temp = a[i];
            a[i] = a[sw];
            a[sw] = temp;
        }
        return a;
    }

    public static void main(String[] args) {
        int i;
        int n[] = {4, 3, 5, 2, 10};
        arr(n);
        for (i = 0; i < 5; i++) {
            System.out.println(n[i]);
        }
    }
}

 

더보기

10

5

4

3

2

 

문제 3

Q. 다음 C 언어로 구현된 프로그램을 분석하여 괄호에 가장 적합한 답을 쓰시오.

 

<실행 결과>

54321000

 

<코드>

#include <stdio.h>

main() 
{
    char ch, str[] = "12345000";
    int i, j;

    for (i = 0; i < 8; i++) {
        ch = str[i];
        if ( (  ) ) {
            break;
        }
    }

    i--;
    for (j = 0; j < i; j++) {
        ch = str[j];
        str[j] = str[i];
        str[i] = ch;
        i--;
    }

    printf("%s", str);
}

 

더보기
ch == '0'

 

 

2020년 1회

문제 1

Q. 다음 Java 언어로 구현한 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

public class Test {
    static int[] arr() {
        int a[] = new int[4];
        int b = a.length;
        for (int i = 0; i < b; i++) {
            a[i] = i;
        }
        return a;
    }

    public static void main(String[] args) {
        int a[] = arr();
        for (int i = 0; i < a.length; i++) {
            System.out.print(a[i] + " ");
        }
    }
}

 

더보기
0 1 2 3

 

문제 2

Q. 다음 C 언어로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력 서식을 준수하시오.)

#include <stdio.h>

main() {
    int c = 1;
    switch(3) {
        case 1: c += 3;
        case 2: c++;
        case 3: c = 0;
        case 4: c += 3;
        case 5: c -= 10;
        default: c--;
    }
    printf("%d", c);
}

 

 

문제 3

Q. 다음 C 언어로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

#include <stdio.h>

void align(int a[]) {
    int temp;
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4 - i; j++) {
            if (a[j] > a[j + 1]) {
                temp = a[j];
                a[j] = a[j + 1];
                a[j + 1] = temp;
            }
        }
    }
}

main() {
    int a[] = { 85, 75, 50, 100, 95 };
    align(a);
    for (int i = 0; i < 5; i++) {
        printf("%d ", a[i]);
    }
}

 

더보기
50 75 85 95 100

 

 

2020년 2회

문제 1

Q. 다음 Python으로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

asia = {'한국', '중국', '일본'}
asia.add('베트남')
asia.add('중국')
asia.remove('일본')
asia.update({'한국', '홍콩', '태국'})
print(asia)

 

더보기
{'한국', '중국', '베트남', '홍콩', '태국'}

 

문제 2

Q. 다음 Java로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

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

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

public class Test {
    public static void main(String[] args) {
        Parent pa = (   ) Child();
        pa.show();
    }
}

 

 

문제 3

Q. 다음 Java로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

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

class B extends A {
    public B(int a) {
        super(a);
        super.display();
    }
}

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

 

더보기
a=10

 

 

2020년 3회

문제 1

Q. 다음 Java로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

public class Test {
    public static void main(String[] args) {
        int i = 0, c = 0;
        while (i < 10) {
            i++;
            c *= i;
        }
        System.out.println(c);
    }
}

 

 

문제 2

Q. 다음 C 언어로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

#include <stdio.h>
int r1() {
    return 4;
}
int r10() {
    return (30 + r1());
}

int r100() {
    return (200 + r10());
}

int main() {
    printf("%d\n", r100());
    return 0;
}

 

 

문제 3

Q. 다음 Java로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

abstract class Vehicle {
    String name;
    abstract public String getName(String val);
    public String getName() {
        return "Vehicle name : " + name;
    }
}

class Car extends Vehicle {
    private String name;
    public Car(String val) {
        name = super.name = val;
    }
    
    public String getName(String val) {
        return "Car name : " + val;
    }

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

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

 

더보기
Vehicle name : Spark

 

문제 4

Q. 다음 Java로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

public class Test {
    public static void main(String[] args) {
        int a = 0, num = 0;
        while (a < 10) {
            a++;
            if (a % 2 == 1) {
                continue;
            }
            sum += a;
        }
        System.out.println(sum);
    }
}

 

 

 

2020년 4,5회

문제 1

Q. 다음 Python으로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

lol = [[1, 2, 3], [4, 5], [6, 7, 8, 9]]
print(lol[0])
print(lol[2][1])
for sub in lol:
    for item in sub:
        print(item, end=' ')
    print()

 

더보기
[1, 2, 3]
7
1 2 3
4 5
6 7 8 9

 

문제 2

Q. 다음은 변수 n에 저장된 10진수를 2진수로 변환하여 출력하는 Java 프로그램이다. 프로그램을 분석하여 괄호(1, 2)에 들어갈 알맞은 답을 쓰시오.

public class Test {
    public static void main(String[] args) {
        int a[] = new int[8];
        int i = 0;
        int n = 10;
        while ( (  1  ) ) {
            a[i++] = (  2  );
            n /= 2;
        }
        for (i = 7; i >= 0; i--) {
            System.out.print(a[i]);
        }
    }
}

 

더보기

① n > 0
② n % 2

 

문제 3

Q. 다음 Java로 구현된 프로그램을 분석하여 괄호(1, 2)에 들어갈 알맞은 답을 쓰시오.

public class Test {
    public static void main(String[] args) {
        int ary[][] = new int[(  1  )][(  2  )];
        int n = 1;
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 5; j++) {
                ary[i][j] = j * 3 + i + 1;
                System.out.print(ary[i][j] + " ");
            }
            System.out.println();
        }
    }
}

 

더보기
① 3
② 5

 

문제 4

Q. 다음 C 언어로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

#include <stdio.h>
main() {
    char* p = "KOREA";
    printf("%s\n", p);
    printf("%s\n", p + 3);
    printf("%c\n", *p);
    printf("%c\n", *(p + 3));
    printf("%c\n", *p + 2);
    
}

 

더보기
KOREA
EA
K
E
M

 

문제 5

Q. 다음 Java로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

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

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

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

 

 

 

2021년 1회

문제 1

Q. 다음 Python으로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

class CharClass:
    a = ['Seoul', 'Kyeongi', 'Incheon', 'Daejeon', 'Daegu', 'Pusan']

myVar = CharClass()
str01 = ' '
for i in myVar.a;
    str01 = str01 + i[0]
print(str01)

 

더보기
SKIDDP

 

문제 2

Q. 다음 Java로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

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

 

더보기

3
1
45
50
89

 

문제 3

Q. 다음 C 언어로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

#include <stdio.h>
main() {
    struct insa {
        char name[10];
        int age;
    } a[] = { "Kim", 28, "Lee", 38, "Park", 42, "Choi", 31 };
    struct insa* p;
    p = a;
    p++;
    printf("%s\n", p->name);
    printf("%d\n", p->age);)
}

 

더보기
Lee
38

 

문제 4

Q. 다음 Java로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

public class Test {
    public static void main(String[] args) {
        int j, i;
        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("+");
            }
        }
    }
}

 

더보기
0+1+2+3+4+5=15

 

 

2021년 2회

문제 1

Q. 다음 Python으로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

a = 100
result = 0
for i in range(1, 3):
    result = a >> i
    result = result + 1
print(result)

 

 

문제 2

Q. 다음 C 언어로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

#include <stdio.h>

main() {
    int res = mp(2, 10);
    printf("%d", res);
}

int mp(int base, int exp) {
    int res = 1;
    for (int i = 0; i < exp; i++) {
        res *= base;
    }
    return res;
}

 

더보기

1024

 

문제 3

Q. 다음 Java로 구현된 프로그램을 분석하여 괄호에 들어갈 알맞은 예약어를 쓰시오.

public class Test {
    public static void main(String[] args) {
        System.out.print(Test.check(1));
    }
    (     ) String check(int num) {
        return (num >= 0) ? "positive" : "negative";
    }
}

 

더보기
static

*static은 클래스 이름으로 메소드에 접근하기 위해 사용하는 예약어이다. 메소드를 사용하기 위해서는 메소드가 포함된 클래스의 객체 변수를 선언한 후 [객체 변수].[메소드] 방식으로 접근해야 하지만, static을 이용하면 객체 변수 없이 [클래스 이름].[메소드]의 방식으로 접근하는 것이 가능해진다.

 

문제 4

Q. 다음 C 언어로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

#include <stdio.h>

int main() {
    int ary[3];
    int s = 0;
    *(ary + 0) = 1;
    ary[1] = *(ary + 0) + 2;
    ary[2] = *ary + 3;
    for (int i = 0; i < 3; i++) {
        s = s + ary[i];
    }
    printf("%d", s);
}

 

 

문제 5

Q. 다음 Java로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

public class ovr1 {
    public static void main(String[] args) {
        ovr1 a1 = new ovr1();
        ovr2 a2 = new ovr2();
        System.out.println(a1.sun(3, 2) + a2.sun(3, 2));
    }
    int sun(int x, int y) {
        retun x + y;
    }
}

class ovr2 extends ovr1 {
    int sun(int x, int y) {
        return x - y + super.sun(x, y);
    }
}

 

 

 

2021년 3회

문제 1

Q. 다음 Java로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

class Connection {
    private static Connection _inst = null;
    private int count = 0;
    public static Connection get() {
        if (_inst == null) {
            _inst = new Connection();
            return _inst;
        }
        return _inst;
    }
    public void count() { count++; }
    public int getCount() { return count; }
}

public class Test {
    public static void main(String[] args) {
        Connection conn1 = Connection.get();
        conn1.count();
        Connection conn2 = Connection.get();
        conn2.count();
        Connection conn3 = Connection.get();
        conn3.count();
    `   System.out.println(conn1.getCount());
    }
}

 

 

문제 2

Q. 다음 C 언어로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

#include <stdio.h>

struct jsu {
    char nae[12];
    int os, db, hab, hhab;
};

int main() {
    struct jsu st[3] = { {"데이터1", 95, 88}, {"데이터2", 84, 91}, {"데이터", 86, 75} };
    struct jsu* p;
    p = &st[0];
    (p + 1)->hab = (p + 1)->os + (p + 2)->db;
    (p + 1)->hhab = (p + 1)->hab + p->os + p->db;
    printf("%d", (p + 1)->hab + (p + 1)->hhab);
}

 

 

문제 3

Q. 다음 Python으로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

x, y = 100, 200
print(x==y)

 

더보기
False

 

문제 4

Q. 다음 C 언어로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

#include <stdio.h>

int main() {
    int* array[3];
    int a = 12, b = 24, c = 36;
    array[0] = &a;
    array[1] = &b;
    array[2] = &c;
    printf("%d", *array[1] + **array + 1);
}

 

 

문제 5

Q. 다음 Java로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

public class Test {
    public static void main(String[] args) {
        int w = 3, x = 4, y = 3, z = 5;
        if ((w == 2 | w == y) & !(y > z) & (1 == x ^ y != z)) {
            w = x + y;
            if (7 == x ^ y != w) {
                System.out.println(w);
            }
            else {
                System.out.println(x);
            }
        }
        else {
            w = y + z;
            if (7 == y ^ z != w) {
                System.out.println(w);
            }
            else {
                System.out.println(z);
            }
        }
    }
}

 

 

 

2022년 1회

문제 1

Q. 다음 Java로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

class A {
    int a;
    int b;
}

public class Main {
    static void func1(A m) {
        m.a *= 10;
    }
    static void func2(A m){
        m.a += m.b;
    }
    public static void main(String args[]){
        A m = new A();
        m.a = 100;
        func1(m);
        m.b = m.a;
        func2(m);
​
    System.out.printf("%d", m.a);
    }
}

 

더보기

2000

 

문제 2

Q. 다음 Java로 구현된 프로그램을 분석하여 괄호에 들어갈 알맞은 답을 쓰시오.

class Car implements Runnable {
    int a;
    public void run() {
        try {
            while (++a < 100) {
                System.out.println("miles travled : " + a);
                Thread.sleep(100);
            }
        } catch(Exception E) { }
    }
}

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

 

 

문제 3

Q. 다음 Python으로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

def func(num1, num2 = 2):
    print('a =', num1, 'b = ', num2)
func(20)

 

더보기

a = 20 b = 2

 

문제 4

Q. 다음은 Python의 리스트 객체에 속한 메소드들에 대한 설명이다. 각 괄호(① ~ ③)에 해당하는 메소드의 이름을 <보기>에서 찾아 쓰시오.

Python에서는 여러 요소들을 한 개의 이름으로 처리할 때 리스트(List)를 사용하며, 각 요소에는 정수, 실수, 문자열 등 다양한 자료형을 섞어 저장할 수 있다. 또한 리스트는 메소드를 활용하여 요소를 추가 및 삭제할 수 있을 뿐만 아니라 정렬하거나 다른 리스트와 병합하는 등의 다양한 작업을 손쉽게 수행할 수 있다.

- (  1  ) : 기존 리스트에 인수의 요소들을 추가하여 확장하는 메소드로, 여러 값을 한 번에 추가할 수 있다.
- (  2  ) : 리스트에서 맨 마지막 또는 인수의 값에 해당하는 위치의 요소를 삭제한 후 반환한다.
- (  3  ) : 리스트에 저장된 각 요소들의 순서를 역순으로 뒤집어 저장하는 메소드이다.

<보기>
(ㄱ) pop()        (ㄴ) push()        (ㄷ) reverse()        (ㄹ) index()        (ㅁ) write()        (ㅂ) sort()        (ㅅ) extend()       
(ㅇ) copy()

 

더보기
(1) (ㅅ)
(2) (ㄱ)
(3) (ㄷ)

 

문제 5

Q. 다음 C언어로 구현된 프로그램을 분석하여 5를 입력했을 때 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

#include <stdio.h>

int func(int a) {
    if (a <= 1) return 1;
    return a * func(a - 1);
}

int main() {
    int a;
    scanf("%d", &a);
    printf("%d", func(a));
}

 

 

문제 6

Q. 다음은 정수를 역순으로 출력하는 C언어 프로그램이다. 예를 들어 1234의 역순은 4321이다. 단, 1230처럼 0으로 끝나는 정수는 고려하지 않는다. 프로그램을 분석하여 괄호(① ~ ③)에 들어갈 알맞은 연산자를 쓰시오.

#include <stdio.h>

int main() {
    int number = 1234;
    int div = 10, result = 0;
    
    while (number (  1  ) 0) {
        result = result * div;
        result = result + number (  2  ) div;
        number = number (  3  ) div;
    }
    printf("%d", result);
}

 

더보기
(1) @!=@ 또는 @>@
(2) @%@
(3) @/@

 

문제 7

Q. 다음 C언어로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

#include <stdio.h>

int isPrime(int number) {
    for (int i = 2; i < number; i++) {
        if (number % i == 0) return 0;
    }
    return 1;
}

int main() {
    int number = 13195;
    int max_div = 0;
    for (int i = 2; i < number; i++) {
        if (isPrime(i) == 1 && number % i == 0) max_div = i;
    }
    printf("%d", max_div);
}

 

 

 

2022년 2회

문제 1

Q. 다음 Java로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

public class Test {
    public static void main(String[] args) {
        int i = 3, k = 1;
        switch(i) {
            case 1: k++;
            case 2: k -= 3;
            case 3: k = 0;
            case 4: k += 3;
            case 5: k -= 10;
            default: k--;
        }
        System.out.print(k);
    }
}

 

 

문제 2

Q. 다음 C언어로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

#include <stdio.h>

struct A {
    int n;
    int g;
}

main() {
    struct A st[2];
    for (int i = 0; i < 2; i++) {
        st[i].n = i;
        st[i].g = i + 1;
    }
    printf("%d", st[0].n + st[1].g);
}

 

 

문제 3

Q. 다음 Python으로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

a = "REMEMBER NOVEMBER"
b = a[0:3] + a[12:16]
c = "R AND %s" % "STR"
print(b + c)

 

더보기

REMEMBER AND STR

 

문제 4

Q. 다음 C언어로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

#include <stdio.h>

int len(char* p);

int main() {
    char* p1 = "2022";
    char* p2 = "202207";
    int a = len(p1);
    int b = len(p2);
    printf("%d", a + b);
}

int len(char* p) {
    int r = 0;
    while (*p != '\0') {
        p++;
        r++;
    }
    
    return r;
}

 

 

문제 5

Q. 다음 C언어로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

#include <stdio.h>

int main() {
    int a[4] = { 0, 2, 4, 8 };
    int b[3];
    int* p;
    int sum = 0;
    
    for (int i = 1; i < 4; i++) {
        p = a + i;
        b[i - 1] = *p - a[i - 1];
        sum = sum + b[i - 1] + a[i];
    }
    printf("%d", sum);
}

 

 

문제 6

Q. 다음 Java로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

class Test {
    public static void main(String args[]) {
        cond obj = new cond(3);
        obj.a = 5;
        int b = obj.func();
        System.out.print(obj.a + b);
    }
}

class cond {
    int a;
    public cond(int a) {
        this.a = a;
    }
    public int func() {
        int b = 1;
        for (int i = 1; i < a; i++) {
            b += a * i;
        }
        return a + b;
    }
}

 

 

2022년 3회

문제 1

Q. 다음 C언어로 구현된 프로그램을 분석하여 배열 <mines>의 각 칸에 들어갈 값을 쓰시오.

#include <stdio.h>
void main() {
    int field[4][4] = { {0, 1, 0, 1}, {0, 0, 0, 1}, {1, 1, 1, 0}, {0, 1, 1, 1} };
    int mines[4][4] = { {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0} };
    int w = 4, h = 4;

    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            if (field[x][y] == 0) continue;
            for (int j = y - 1; j <= y + 1; j++) {
                for (int i = x - 1; i <= x + 1; i++) {
                    if (chkover(w, h, j, i) == 1) {
                        mines[i][j] += 1
                    }
                }
            }
        }
    }
}

int checkover(int w, int h, int j, int i) {
    if (i >= 0 && i < w && j >= 0 && j < h) return 1;
    return 0;
}
배열 <field>
0 1 0 1
0 0 0 1
1 1 1 0
0 1 1 1

배열 <mines>
       
       
       
       

 

더보기
1 1 3 2
3 4 5 3
3 5 6 4
3 5 5 3

 

문제 2

Q. 다음 Java로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

public class Test {
    public static void main(String[] args) {
        int result[] = new int[5];
        int arr[] = { 77, 32, 10, 99, 50 };

        for (int i = 0; i < 5; i++) {
            result[i] = 1;

            for (int j = 0; j < 5; j++) {
                if (arr[i] < arr[j]) {
                    result[i]++;
                }
            }
        }
        for (int k = 0; k < 5; k++) {
            System.out.print(result[k]);
        }
    }
}

 

더보기

24513

 

문제 3

Q. 다음 Python으로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

a = [1, 2, 3, 4, 5]
a = list(map(lambda num : num + 100, a))
print(a)

 

더보기

[101, 102, 103, 104, 105]

 

문제 4

Q. 다음 C언어로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

#include <stdio.h>
void main() {
    int s, el = 0;
    for (int i = 6; i <= 30; i++) {
        s = 0;
        for (int j = 1; j <= i / 2; j++) {
            if (i % j == 0) {
                s = s + j;
            }
        }
        if (s == i) {
            el++;
        }
    }
    printf("%d", el);
}

 

 

문제 5

Q. 다음 JAVA로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

public class Test {
    static int[] mkarr() {
        int[] tmpArr = new int[4];
        for (int i = 0; i < tmpArr.length; i++) {
            tmpArr[i] = i;
        }
        return tmpArr;
    }

    public static void main(String[] args) {
        itn[] arr;
        arr = mkarr();
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]);
        }
    }
}

 

더보기

0123

 

문제 6

Q. 다음 JAVA로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)

public class Test {
    public static void main(String[] args) {
        int r = 0;
        for (int i = 1; i < 999; i++) {
            if (i % 3 == 0 && i % 2 == 0) {
                r = i
            }
        }
        System.out.print(r);
    }
}

 

 

 

 

 

728x90
그리드형(광고전용)
⚠️AdBlock이 감지되었습니다. 원할한 페이지 표시를 위해 AdBlock을 꺼주세요.⚠️
starrykss
starrykss
별의 공부 블로그 🧑🏻‍💻


📖 Contents 📖