2020년 1회 - 4번 문제
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 |
class Main { 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 | |
프로그램은 Main 클래스로 시작하고, arr 메서드와 main 메서드를 포함하고 있다. arr 메서드는 int 형 배열을 반환하는 정적 메서드로 메서드 안에서는 크기가 4인 a 배열을 생성하고, b 변수에 배열의 길이를 저장한다. 그리고 for 루프를 사용하여 a 배열의 각 요소에 i 값을 할당한다. i 값은 배열의 인덱스로 사용되고, 0 부터 b (배열의 길이) 보다 작은 값(4보다 작은 3)을 가지며 최종적으로 a 배열을 반환한다. main 메서드는 프로그램의 실제 실행 부분으로 arr 메서드를 호출하여 반환된 배열을 a 변수에 저장한다. 그리고 for 루프를 사용하여 배열의 각 요소를 출력하며 출력은 공백으로 구분되고, 배열의 값을 순서대로 출력한다. 07 : return a[];를 사용하면 컴파일 오류가 발생된다. 배열을 반환할 때는 배열 이름만 사용해야 한다. |
2020년 2회 - 5번 문제( (가)에 들어갈 알맞은 답을 쓰시오)
01 02 03 04 05 06 07 08 09 10 11 12 13 |
class Parent{ void show(){System.out.println("parent");} } class Child extends Parent{ void show() {System.out.println("child");} } class Main { public static void main(String args[]) { Parent pa=(가) Child(); pa.show(); } } |
new | |
2020년 2회 - 19번 문제
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
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); super.display(); } } public class Main { public static void main(String[] args){ B obj = new B(10); } } |
a=10 | |
2020년 3회 - 2번 문제
01 02 03 04 05 06 07 08 09 10 |
public class Main{ public static void main(String[] args){ int i=0, c=0; while (i<10){ i++; c*=i; } System.out.println(c); } } |
0 | |
2020년 3회 - 15번 문제
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 22 23 24 25 |
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 Main { public static void main(String[] args){ Vehicle obj = new Car("Spark"); System.out.print(obj.getName()); } } |
Vehicle name : Spark | |
2020년 3회 - 17번 문제
01 02 03 04 05 06 07 08 09 10 11 12 |
public class Main { public static void main(String[] args){ int i=0, sum=0; while (i<10){ i++; if(i%2 ==1) continue; sum += i; } System.out.println(sum); } } |
30 | |
2020년 4회 - 7번 문제(다음은 변수 n에 저장된 10진수를 2진수로 변환하여 출력하는 java프로그램이다. 프로그램을 분석하여 ( 1번 )( 2번 )빈칸에 알맞은 답을 쓰시오.
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 |
class Main { 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]); } } } |
(1번) : n>0 (2번) : n%2 |
|
2020년 4회 - 8번 문제(가, 나의 답을 쓰시오.)
01 02 03 04 05 06 07 08 09 10 11 12 13 |
public class Main { public static void main(String[] args) { int ary[][] = new int[가][나]; 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 |
|
2020년 4회 - 19번 문제
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 |
class Parent{
public int compute(int num){ if(num <=1) return num; return compute(num-1) + compute(num-2); } } class Child extends parent { public int compute(int num){ if(num<=1) return num; return compute(num-1) + compute(num-3); } } class Main{ public static void main (String[] args){ Parent obj = new Child(); System.out.print(obj.compute(4)); } } |
1 | |
2021년 1회 - 7번 문제
01 02 03 04 05 06 07 08 09 10 |
public class Main{ public static void main(String[] args){ int arr[][] = new int[][]{{45,50,75},{89}}; System.out.println(arr[0].length); System.out.println(arr[1].length); System.out.println(arr[0][0]); System.out.println(arr[0][1]); System.out.println(arr[1][0]); } } |
3 1 45 50 89 |
|
2021년 1회 - 17번 문제
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 |
public class Main { 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("+"); } } } } |
0+1+2+3+4+5=15 | |
2021년 2회 - 17번 문제((가)에 알맞은 예약어를 쓰시오)
01 02 03 04 05 06 07 08 09 |
public class Main { public static void main(String[] args){ System.out.print(Main.check(1)); } (가) String check (int num) { return (num >= 0) ? "positive" : "negative"; } } |
static | |
2021년 2회 - 19번 문제
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 |
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){ return x + y; } } class ovr2 extends ovr1 { int sun(int x, int y){ return x - y + super.sun(x,y); } } |
11 | |
2021년 3회 - 1번 문제
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
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 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(); System.out.print(conn1.getCount()); } } |
3 | |
2021년 3회 - 11번 문제
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 |
public class Main{ 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 | |
2022년 1회 - 1번 문제
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
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 | |
2021년 1회 - 5번 문제((가)에 들어갈 알맞은 답을 쓰시오)
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 |
class Car implements Runnable{ int a; public void run(){ try{ while(++a<100){ System.out.println("miles traveled :" +a); Thread.sleep(100); } } catch(Exception E){} } } public class Main{ public static void main(String args[]){ Thread t1 = new Thread(new (가)()); t1.start(); } } |
(가) : Car | |
2022년 2회 - 7번 문제
01 02 03 04 05 06 07 08 09 10 11 12 13 14 |
class Main { public static void main(String args[]) { int i=3, 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 | |
2022년 2회 - 17번 문제
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 |
class Conv{ 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 class Main { public static void main(String args[]) { Conv obj=new Conv(3); obj.a=5; int b=obj.func(); System.out.print(obj.a+b); } } |
2022년 3회 - 4번 문제
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 |
public class Test{ public static void main(String[] args){ int []result = 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++) { printf(result[k]); } } } |
24513 | |
2022년 3회 - 19번 문제
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 |
public class Main { static int[] MakeArray(){ int[] tempArr = new int[4]; for(int i=0; i<tempArr.Length;i++){ tempArr[i] = i; } return tempArr; } public static void main(String[] args){ int[] intArr; intArr = MakeArray(); for(int i=0; i < intArr.Length; i++) System.out.print(intArr[i]); } } |
0123 | |
2022년 3회 - 20번 문제
01 02 03 04 05 06 07 08 09 10 11 |
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 | |
2023년 1회 - 1번 문제
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 |
class Static{ public int a=20; static int b=0; } public class Main { public static void main(String[] args) { int a=10; Static.b=a; Static st=new Static(); System.out.println(Static.b++); System.out.println(st.b); System.out.println(a); System.out.println(st.a); } } |
10 11 10 20 |
|
2023년 1회 - 18번 문제
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
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 Main { public static void main(String[] args){ Vehicle obj = new Car("Spark"); System.out.print(obj.getName()); } } |
Vehicle name : Spark | |
2023년 1회 - 20번 문제
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
class Parent { int x = 100; Parent() { this(500); } Parent(int x) { this.x = x; } int getX() { return x; } } class Child extends Parent { int x = 1000; Child() { this(5000); } Child(int x) { this.x = x; } } public class Main { public static void main(String[] args) { Child obj = new Child(); System.out.println(obj.getX()); } } |
500 | |
'자격증 > 실기' 카테고리의 다른 글
SQL 기출 해설 (0) | 2023.06.26 |
---|---|
Python 언어 기출 해설 (0) | 2023.06.26 |
C 언어 기출 해설 (0) | 2023.06.26 |
댓글