exam questions

Exam 1z0-808 All Questions

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

Exam 1z0-808 topic 1 question 173 discussion

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

Given the code fragment:

Which modification enables the code to print 54321?

  • A. Replace line 6 with System.out.print (--x);
  • B. At line 7, insert x --;
  • C. Replace line 5 with while (is Available(--x)) {
  • D. Replace line 12 with return (x > 0) ? false : true;
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

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, 3 weeks ago
Selected Answer: A
A is correct
upvoted 1 times
...
amit_lad88
1 year ago
Correct answer is C int x = 6; while (isAvailable(--x)) { System.out.print(x); //x--; // Answer B - Its ok. } This will print 54321. if we choose option A then output will be 543210
upvoted 1 times
amit_lad88
1 year ago
My bad. The above answer is correct only when the below method is used public static boolean isAvailable(int x) { return x-- > 0 ? true : false; } Final correct is A
upvoted 1 times
...
...
zhiradev
1 year, 2 months ago
Selected Answer: A
Tested A is correct
upvoted 1 times
...
carloswork
2 years, 2 months ago
Selected Answer: A
Answer is A. public class Test { public static void main(String[] args) { int x = 6; while (isAvailable(x)) { System.out.print(x); // Replace this, by Option A "System.out.print (--x);" } } public static boolean isAvailable(int x) { return --x > 0 ? true : false; } }
upvoted 1 times
...
UAK94
2 years, 3 months ago
A. { int x=6; while (isAvailable(x)) { System.out.println(--x); } }
upvoted 1 times
...
iSnover
2 years, 3 months ago
Selected Answer: A
The correct answer is letter A, if it were alternative C, it would return an OutOfMemoryException because it would print 6 infinitely. In order to decrease the variable, the decrease must occur in the for loop and before printing, if you put "--x" the decrease occurs instantly, as was done in alternative A.
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