405,121 views
31 votes
31 votes
Consider the following code segment in which the int variable x has been properly declared and initialized.if (x % 2 == 1){System.out.println("YES");}else{System.out.println("NO");}Assuming that x is initialized to the same positive integer value as the original, which of the following code segments will produce the same output as the original code segment?I.if (x % 2 == 1){System.out.print("YES");}if (x % 2 == 0){System.out.println("NO");}II.if (x % 2 == 1){System.out.println("YES");}else if (x % 2 == 0){System.out.println("NO");}else{System.out.println("NONE");}III.boolean test = x % 2 == 0;if (test){System.out.println("YES");}else{System.out.println("NO");}A I onlyB II onlyC III onlyD I and II onlyE I, II, and III

User Doug Knesek
by
3.1k points

1 Answer

29 votes
29 votes

Answer:

The correct answer is D: I and II only.

User Melenie
by
3.5k points