정보처리기사 C언어, Java, Python, SQL 기출문제 모음
22년 1회
19. 다음 Java로 구현된 프로그램을 분석하여 그 실행결과를 쓰시오.
| 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); |
| } |
| } |
22년 1회
20. 다음 Java로 구현된 프로그램을 분석하여 그 실행결과를 쓰시오.
| 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); |
| } |
| } |
22년 2회
10. 다음 Java로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오.
| 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); |
| } |
| } |
22년 2회
16. 다음 Java로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오.
| 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); |
| } |
| |
| } |
22년 3회
3. 다음 Java로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오.
| 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.print("%d",a[i]); |
| } |
| } |
22년 3회
15. 다음 JAVA로 구현된 프로그램을 분석하여 그 실행결과를 쓰시오.
| 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<3;i++) |
| for(int j=0; j<3;j++) |
| a[i][j]=0; |
| } |
| |
| static void data(int a[][]){ |
| int v=1; |
| for(int i=0; i<3;i++) |
| for(int j=i; j<3;j++) |
| a[i][j]=v++; |
| } |
| |
| static void prnt (int a[][]){ |
| for(int i=0; i<3;i++){ |
| for(int j=0; j<3;j++){ |
| if(a[i][j]==0) |
| System.out.printf(" "); |
| else |
| System.out.printf("%d", a[i][j]); |
| } |
| System.out.println(); |
| } |
| } |
| } |
23년 1회
12. 다음 코드의 출력결과를 쓰시오
| 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); |
| } |
| } |
23년 2회
15. 출력결과
| 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"); |
| } |
| } |
| } |
23년 3회
10. 출력결과
| 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(); |
| } |
| } |
23년 3회
15. 출력결과
| 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<5; i++) { |
| func(i); |
| } |
| System.out.print(a); |
| } |
| } |
23년 3회
17. 출력결과
| 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)); |
| } |
| } |
24년 1회
4. java 출력결과
| 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); |
| |
| } |
| } |
24년 1회
13. Java 빈칸에 들어갈 것을 쓰시오
| public class Test { |
| public static void main(String [] args) { |
| int totalcnt = 10, totalleg = 26; |
| int duckcnt, pigcnt; |
| for(duckcnt = 1; duckcnt < totalcnt; duckcnt++) { |
| pigcnt = totalcnt -(가); |
| if((2 * duckcnt) + (4 *(나)) == totalleg) { |
| System.out.printf("%d %d", duckcnt, pigcnt); |
| break; |
| |
| } |
| } |
| } |
| } |
24년 2회
4. Java 실행결과
| 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)); |
| |
| } |
| |
| } |
24년 3회
7. Java 실행결과
| 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); |
| } |
| } |
24년 3회
18. Java 출력결과
| 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<T> { |
| T value; |
| public Collection(T t) { |
| value = t; |
| } |
| public void print() { |
| new Printer().print(value); |
| |
| } |
| } |
| } |
정보처리기사 C언어, Java, Python, SQL 기출문제 모음