Question

Question 26 options: How many times will the while loop execute? Type the answer as an...

Question 26 options:

How many times will the while loop execute? Type the answer as an integer, "infinity" or "unknown".

int x = 3;
while (x < 370)
{
System.out.print(x + " ");
x *= x;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The while loop will run 3 times.

Explanation:

The while loop runs as long as the condition specified is true.

The condition in the code is x<370

So while loop will keep running till x remains less than 370 .

1st run:

  1. x is 3 which is less than 370.
  2. System.out.print will display the value 3 in output
  3. The value of x will then change to 3 (3*3)

2nd run:

  1. x is 9 which is less than 370.
  2. System.out.print will display the value 9 in output
  3. The value of x will then change to 81(9*9)

3rd run:

  1. x is 81 which is less than 370.
  2. System.out.print will display the value 81 in output
  3. The value of x will then change to 6561 (81*81)

After the 3rd run the while loop will be terminated as the value of x will be 6561 will is not less than 370.

Output of the above code is:

3 9 81

Add a comment
Know the answer?
Add Answer to:
Question 26 options: How many times will the while loop execute? Type the answer as an...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT