Question

When the Java source code below is executed, how many times is the boolean expression (j > 0) evaluated? int i 1; do { int j

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

i =1 at first j =35

condition is j>0 and inside the loop we have the condition j=j/2. So everytime j gets divided by 2 and we check the condition

since it is integer division so result will also be integer .The values of j where condition j>0 is checked is

j=35,17,8,4,2,1,0

0 is included beacuse 0>0 is false but condition check is done .

So for i=1 there will be 7 evaluation of j>0.

Similarly for i=2,3

Now when i=4 the condition i<=3 is not satisfied so it breaks from the loop therefore total is 7+7+7=21.

Answer is none of the other answers are correct.

Add a comment
Know the answer?
Add Answer to:
When the Java source code below is executed, how many times is the boolean expression (j...
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