ocajp 자격증 (Oracle Certified Associate Ja
자바 ocjap 문제 해설 - 연산자
xemaker
2020. 2. 24. 21:03
Given the code fragment:
public class Operator15 {
public static void main(String[] args) {
int x=100;
int a=x++;
int b=++x;
int c=x++;
int d=(a<b) ? (a<c) ? a : (b<c)? b : c;
System.out.println(d);
}
}
What is the result?
A. 100
B. 101
C. 102
D. 103
E. Compilation fails
정답: E
해설:
컴파일시 c; 부분에서 에러가 난다.
Syntax error, insert ": Expression" to complete Expression
즉, (a<b) ? (a<c) ? a : (b<c)? b : c : a; 이런식으로 처음 (a<b) ? 에 false에 해당하는 값이 있어야 한다.