3단원 쪽지시험 정답: 연산자¶
문제 1¶
9, 6이다. 첫 피연산자는 4를 사용 후 5, 두 번째는 먼저 6이 되어 4+6이다.
문제 2¶
x = (byte)(x + 30);
x += 30;.
문제 3¶
true. 우선순위는 !, &&, || 순이다.
문제 4¶
0b0110, 10진수 6.
문제 5¶
String result = n % 2 == 0 ? "even" : "odd";
문제 6¶
x *= 2 + 1은x = x * (2 + 1)이다.
문제 7¶
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("A: "); int a = sc.nextInt();
System.out.print("B: "); int b = sc.nextInt();
int max = a > b ? a : b;
int min = a > b ? b : a;
System.out.printf("max=%d, min=%d%n", max, min);
}
}