Exam 1z0-808 All QuestionsBrowse all questions from this exam
Question 20

Given the code fragment:

Which modification enables the code to print 54321?

    Correct Answer: B

    To enable the code to print 54321, add `x--;` at line 7 within the `while` loop. This decrements the value of `x` after each print operation, ensuring that `x` is printed starting from 5 and decrementing down to 1. The method `isAvailable(x)` checks if `x` is greater than 0 before decrementing it, so the loop continues to execute correctly until `x` is decremented below 1.

Discussion
hyodaeunOption: B

Answer is B

Mamlouk_MedOption: B

answer is B, Sur la ligne 12 du programme, l'utilisation de "x--" dans la méthode isAvailable n'affecte pas la variable x de la méthode principale, car Java est toujours "pass by value". L'option A fera la sortie "43210". Option B, vous pouvez générer avec succès "54321". Option C, cette logique est la même que l'option A. L'option D, tant que la boucle ne sera pas exécutée.

7df49fbOption: B

B changes made to x inside the isAvailable method do not affect the x in the main method because Java passes arguments by value.

arjunrawatirissoftwareOption: B

Answer - B

DarGrinOption: B

B is only one correct answer

dsmsOption: B

Correct answer is B

Anixtc

This is majorly helpful

Vicky_65Option: B

option is B

willokansOption: B

Answer is B x-- will allow the loop to iterate from 5 to1 until x !> 0

carlosworkOption: B

Answer is B. To test: public class Test { public static void main(String[] args) { int x = 5; while(isAvailable(x)) { System.out.print(x); x--; // Answer B - Its ok. } } public static boolean isAvailable (int x) { return x-- > 0 ? true : false; } }

acyutaOption: B

B is correct. It will be in sync with what is happening inside the function isAvailable

bakhdakOption: B

Answer is B

archer1903Option: B

Answer is B

archer1903Option: B

Answer is B

David2606Option: B

answer is B, la respuesta correcta es B

oca808reattemptOption: B

Ans is B

starhappykcsOption: B

Answer is B