자격증/정보처리기사 실기 - 기출문제
[정보처리기사 실기] 2021년 3회 17 - 프로그래밍 [JAVA]
Ayel
2025. 7. 18. 07:12
17 다음 JAVA로 구현된 프로그램을 분석하여 그 실행 결과를 쓰시오. (단, 출력문의 출력 서식을 준수하시오.)
public class Test {
public static void main(String[] args) {
int 1=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);
}
}
}
답
더보기
7
해설
| 코드 | 실행순서 및 해석 | ||
| 1 | public class Test { | ||
| 2 | public static void main(String[] args) { | ||
| 3 | int 1=3, x=4, y=3, z=5; | ||
| 4 | if((w==2|w==y)&!(y>z)&(1==x^y!=z)){ | 1 | 양쪽이 참이어야 참이 된다 w==2|w==y → false or true → true !(y>z) → !false → true 1==x^y!=z → 1==x는 false이고 y≠z는 true 이기 때문에 ^(exclusive) true ⇒ true |
| 5 | w = x+y; | 2 | w에는 7을 넣는다 |
| 6 | if(7==x^y!=w) | 3 | 7==x는 false이고 y≠w는 true이므로 ^exclusive true가 된다 |
| 7 | System.out.println(w); | 4 | w 출력 → 4 |
| 8 | else | ||
| 9 | System.out.println(x); | ||
| 10 | } | ||
| 11 | else { | ||
| 12 | w = y+z; | ||
| 13 | if(7==y^z!w) | ||
| 14 | System.out.println(w); | ||
| 15 | else | ||
| 16 | System.out.println(z); | ||
| 17 | } | ||
| 18 | } | ||
| 19 | } | ||