You are on page 1of 12
Output Finding Questions: QL. Write the output of the following code Ans. 2-74 Q.2. White the output of the following code int 1 Jwhile(+4i<5), System out printin({); Ans £24 Q3. What will be the value of and after execution of the following code Ans j=104e10 Q4. How many times the following loop gets executed? mt whilei>20) { statements } Ans: zero times Q.5, How many times the following loop gets executed? i=, dof Jistatements Jwhile(i>20), ‘Ans. one time Q.6. What will be the contents of TextField after executing the following statement int mum—4; num=num+l; iffnum>S) jTextFieldl setText(Integer toString(num)), se {TextField setTText(Integer toString(num"4)); Ans 20 29 Q7 find the output int number!=7,number2=8; int second=73, if{number1 >O)jmumber?>5) if{number1>7) jTextFieldl setText(“code worked”); se jTextFieldl_setText(“code might work’), else jTextField1 setText(“code will not work —”); Ans. code ‘might work Q8. How many times will the following loop get executed? } Qo. What will be the content of the jTextAreal after executing the following cade? int num=1; do { jTextAreal setText(Integer to String++num)+"\n"), D Ans. 10 Q.10. Give the output for the following code fragment: v=20; dof jOptionPane showMessageDialoginumm,.v+""); jwhile(v<50), jOptionPane showMessageDialoginumm,v+""); Ans infinite loop Q.1. Give the value after executing following java code Also find how many times the following loop wall execute? inta=10, int int 2-5, int y-6, iar zeaty, alse zy, aratl, } Ans. x=11 30 Q.12.What wall be the output produced by following code fragment? float 2-9; float y=5, int int\oxly), switch¢2) { case Laat case 2: xext3, default: x=c+1, } System, out printin(“value of "+);, Ans. 15 Q.13 Predict the output of the following code fragment aehitt, Jwhileti<=5), Ans. 6 Q.13. What will be the values of x and y after executing the following expressions int x=20,y-35, meytt txt, yetty+ tx, Ans x=56, y=93 Q.14. What will be the values of x and y after executing the following expressions int y=-1, System out printin('x:"+(-y-), System out printin("y-"+y), Ans. x:= -1 y=2 Q15. What will be the values of x and y after executing the following expressions intx=45, Raataht, System out printing), int y=45; yryttty, System out printin(y), Ans 2-90, y=91 Q.16. What values will be assigned to the variable ua,ub,uc and fail after execution of the following program segment int i=0,ua—0,ub=0 ue-0, il vwhileti<=5)( switch++) { case 1-+40a, case 2-++ub:uct+: break, 31 case 3, case 4-++ucuat+ub++ break, default ++fail; } Ans. ual, ub=1, uo-0 Q.17. Predict an output of the following code fragment inti=1 j=O.0-0; while)i<4) { for(=1jelj++) { n=l, init], } System out printin(n), } Ans. 6 Q.18. Give the output of the following code int m=100; vwhile(m>0) Frio breaks, m=m-10, } System out printin(“m is “+m); Ans. 0 Error Finding Questions: Q.1. The following cade has some errors. Rewrite the corrected code while)>i {jTextField! getText(j is greater"); jet l } JOptionPane showMessageDialog(“Hello”), Q2. Identify the errors: switch( ch) we case ‘a case ‘A’ case"e’ case “E’ case? case ‘E” case “u" case ‘U"-++vowels, break, defeult-++others, 32 Ans: Two case constant doesn't have the same value Q3 int mts, ifs) jTextPield1 setText(“Iand j are equal”), ‘se TextField! settext(* [and j are unequal”); Ans. intij=5; ise, iti) {TextField setText(“I and j are equal”); se jTextFieldl settext(* I andj are unequal”), (Q4. Reunite the code after making correction. Underline the correction Int sumvalue;inet, Inti F =10;i+) Sum=sum+l, Inct++, Ans int sum,valueinet, inti; for(i=0.i<=10;i++) sum=sumti; inct++, Q'5. The following code has some error(s) Rewrite the correct code underlining all the corrections made. Int y=3; Sunray case 1: System out printin(*yes its one”), case >2: System out printin("yes it is more than two"), break, case else: System out printin( “invalid number”), ‘Ans. int y=3, ew case 1 : System out printin(“yes its one”), break, case 2: System out printin(“yes its more than two”), break, default: System out printin( “invalid mumber”), Q.6. Reunite the following java code after undertining the correction made int 0; int n=Integer parselnt(jLabell getText( )); 33 ‘Ans. int 2-0, int n=Integer parselnt(jLabell getText()); Q7. find out errors if any: m=l.n-0, For(.mtn<19;++n) System out printin(“hello”), M-m+10; Ans. m=L:n=0; for( m+n<19,++n) System out printin(“hello”), mam+10; Q8. The following code has some error(s) Rewrite the correct code underlining all the corrections made System out print(“two"), While(y>1) Ans int y=6, System out print(“two"), whilety>1). Rewrite Questions QU. Rewnite the following program code using for loop. int I,sum=0; while(I<10) Q.2. rewnite the following code using while loop inti; form Licd.ie+) { for(j=1j0) ra%l0; if(t%4—0) slt=r, dse st4=r, 39 System out printin¢* ‘What will be the output of the program? int nos=100; while(nos>=45) { iffn0s%5—0) nos+=10; nost=20, ‘What will be the output of the i) byte b, double d=417.35; b(byte)d, System out printin(b), (ii) int m=100; int n=300, while(++m< —-n) System out printin(me""'+n), (i) int 3=10,y=20, i(e<=y)||e=5)> 10) System out printin(), se System out printin(y), (w) ant==10; float y=10.0, System out printin((x>y)?true false), 40

You might also like