[JAVA] 24년 기출 문제 풀이(1회, 2회)

2024. 10. 13. 21:56·정보처리기사[실기]

[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

 

// 실행순서를 나열하시오

class Parent{
	int x,y;
    
    Parent(int x, int y){ (가)
		this.x=x;
        this.y=y;
    }
    
    int getT(){ (나)
    	return x*y;
    }
}

class Child extend Parent{
	int x;
    
    Child(int x){ (다)
    	super(x+1, x);
        this.x=x;
    }
    
    int getT(int n){ (라)
    	return super.getT()+n;
    }
}

class Main{
	public static void main(String[] args){ (마)
    	Parent parent = new Child(3); (바)
        System.out.println(parent.getT()); (사)
    }
}
더보기

정답 : 마 - 바 - 다 - 가 - 사 - 나

 

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);
    }
    
    public void print(){
    	System.out.println(po*po);
    }
}

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

정답 : 9


[24년 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);
        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

 

* 참조 비교하는 형식이기 때문에 같은 배열을 가지고 있지만, 다른 객체이므로 N이 출력

 

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));
    }
}

interface Number{
	int sum(int[] a, boolean odd);
}

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;
    }
}
더보기

정답 : 25, 20

 

[풀이]

홀수 짝수 합산 문제

odd가 true일 때, a[i] % 2 != 0 이면 a[i]는 홀수

result에 홀수 더하기

 

odd가 false일 대, a[i] % 2 == 0 이면 a[i]는 짝수

result에 짝수 더하기

 

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 c + result;
        }
        return result;
    }
}
더보기

정답 : dcba

 

[풀이]

https://www.youtube.com/watch?v=IvdrC80ds_M&list=PLYdThbnQN0eLY1WspibwMrHJkkoEtTF5J&index=2

참고..하쇼..

 

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

정답 : S

 

저작자표시 변경금지 (새창열림)

'정보처리기사[실기]' 카테고리의 다른 글

[Python] 21년 기출 문제 풀이 (1회 ~ 3회)  (0) 2024.10.14
[Python] 20년 기출 문제 풀이(1회 ~ 4회)  (0) 2024.10.14
[JAVA] 23년 기출 문제 풀이 (1회 ~ 4회)  (3) 2024.10.13
[JAVA] 22년 기출 문제 풀이 (1회 ~ 3회)  (0) 2024.10.13
[JAVA] 21년 기출 문제 풀이 (1회 ~ 4회)  (1) 2024.10.11
'정보처리기사[실기]' 카테고리의 다른 글
  • [Python] 21년 기출 문제 풀이 (1회 ~ 3회)
  • [Python] 20년 기출 문제 풀이(1회 ~ 4회)
  • [JAVA] 23년 기출 문제 풀이 (1회 ~ 4회)
  • [JAVA] 22년 기출 문제 풀이 (1회 ~ 3회)
microsaurs
microsaurs
개발 스터디로그입니다. 공부한 내용을 정리해서 올립니다 ㅇ-ㅇ
  • microsaurs
    microsaurs.devlog
    microsaurs
  • 전체
    오늘
    어제
    • 분류 전체보기 (141) N
      • Side Project (3) N
      • Algorithm Study (39)
      • JAVA (8)
      • Swift (11)
      • Python (21)
      • CS (5)
      • React (3)
      • 리얼클래스 studylog (27)
      • 정보처리기사[실기] (23)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    자바알고리즘
    리얼학습일기
    스위프트기초
    파이썬문법
    study
    ios프로그래밍을위한스위프트기초
    정보처리기사
    정처기실기
    javaalgorithm
    정보처리기사프로그래밍언어
    ios프로그래밍
    더오피스
    프로그래머스
    Java
    나도코딩
    파이썬
    파이썬기초
    Python
    영어독학
    알고리즘
    Algorithm
    프로그래밍언어
    영어회화
    SWIFT
    리얼클래스
    ios개발
    타일러영어
    javaStudy
    The Office
    정보처리기사실기
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.0
microsaurs
[JAVA] 24년 기출 문제 풀이(1회, 2회)
상단으로

티스토리툴바