Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
1.2k views
in Information Technology by (53.3k points)

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.

1 Answer

+1 vote
by (53.1k points)
selected by
 
Best 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. 

No related questions found

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...