ExamCompetition Forum Question Papers Ask A Question Mock Test Learn & Earn Sign Up Login Menu



0 vote

1. public class Test{2. public static void main(String [] args){3. int x = 0;4. // insert code here5. do{ } while(x++ < y);6. System.out.println(x);7. }8. }Which option, inserted at line 4, produces the output 12?

Asked on by | Votes 0 | Views: 2274 | Tags: computer science     | java programming     | flow control     | Add Bounty

1. public class Test{2. public static void main(String [] args){3. int x = 0;4. // insert code here5. do{ } while(x++ < y);6. System.out.println(x);7. }8. }Which option, inserted at line 4, produces the output 12?

A).  int y = x;

B).  int y = 10;

C).  int y = 11;

D).  int y = 12;

E).  None of the above will allow compilation to succeed.


Share on Facebook      Share on Whatsapp       Share on Twitter




1 answers

0 vote
Answered by on | Votes 0 |

 int y = 11;



x reaches the value of 11, at which point the while test fails.
x is then incremented (after the comparison test!), and the println() method runs.
Hence, choice A, B, D, E, and F are incorrect based on the above point.

Join Telegram Group




Answer This Question

Name:
Email:
Answer :
Sum of (5+3)
Submit: