1.

Will the output from the following two code be any different?First Code:int x=2,y=40;while(y<=x) {jTextField1.setText(""+x);x=x+8;}Second Code :int x=2,y=40;do{jTextField1.setText(""+x);x=x+8;} while(y<=x);Give reasons for your answer.

Answer»

Yes it will be different as in First Code there will be no output while in Second Code the output will be 2 because in while loop condition is false in the beginning so control will not come inside the loop even for once while in do while loop, loop will be executed at least once even if the condition is false. 



Discussion

No Comment Found

Related InterviewSolutions