Ask Question
18 February, 18:54

If number is 20, what is printed to the console after this code is executed?

for (int i = 3; i < = number; i + = 2)

{

if (number % i = = 0)

{

System. out. println (i);

if (i = = number)

System. out. println ("special");

break;

}

}

a. 5

b. 5

5

special

c. 20

special

d. 5

special

e. 2

+5
Answers (1)
  1. 18 February, 19:16
    0
    Option a is the correct answer for the above question

    Explanation:

    The above question code has one for-loop which runs two times only for the value of number=20. It is because when the if-condition will true then the loop will be exit because it holds the break statement which exits the for-loop when the if-condition will be true. So when the first time 20 will divide by 3 then if-condition will fail, but when the 20 will be divide by the 5, then the if condition will be true and the 5 will be printed as output. Then the second if-condition will false because it will be true for the 20 value of i. Hence option a is the correct answer while the other is not correct because others will not hold the output of this code.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “If number is 20, what is printed to the console after this code is executed? for (int i = 3; i < = number; i + = 2) { if (number % i = = 0) ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers