exam questions

Exam 1z0-808 All Questions

View all questions & answers for the 1z0-808 exam

Exam 1z0-808 topic 1 question 185 discussion

Actual exam question from Oracle's 1z0-808
Question #: 185
Topic #: 1
[All 1z0-808 Questions]

Given the code fragment:

What is the result?

  • A. 11
  • B. 10
  • C. 12
  • D. A compile time error occurs.
Show Suggested Answer Hide Answer
Suggested Answer: C 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
MPignaProTech
2 months, 2 weeks ago
Selected Answer: C
Answer is C for X is incremented 2 times : int y = ++x nd if (...... y<= ++x)
upvoted 1 times
...
samarrrr
1 year, 8 months ago
A is the right one
upvoted 2 times
...
carloswork
2 years, 2 months ago
Selected Answer: C
Answer is C. To test: public static void main(String[] args) { int x = 10; int y = ++x; int z = 0; if(y >= 10 | y <= ++x) { z = x; } else { z = x++; } System.out.println(z); }
upvoted 3 times
...
iSnover
2 years, 3 months ago
Selected Answer: C
The correct answer is the letter C, notice that in the instantiation line of the variable "y" and in the if condition the x receives 2 times a "++", that is, the variable x had an increment in its value 2 times having the value of 12. As if gave true, the value of z was equal to that of x giving the answer 12. The code compiles normally, the difference between using "|" or "||" in if is that the first option when compiling tests the 2 possibilities, but "II" will give true or false testing only the first condition, this was done to run the code faster on some occasions when it is not necessary to test the second condition if the first one already delivers whether it is true or false.
upvoted 1 times
...
alex_au
2 years, 3 months ago
It really depends on the if statement whether or not there is typo. If it is "if(y >= 10 || y <= ++x)", then the answer is 11, as y = 11 so y >= 10, based on short-circuiting, y <= ++x is not executed and z is assigned to the value of 11. If it is "if(y >= 10 | y <= ++x)", now the | is the bitwise operator so the two sides of the operators must be executed. As two sides are true, true | true is true and x now becomes 12 (due to the y <= ++x). Thus z is assigned to 12.
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago