Computer Science, asked by himanshu112263, 5 months ago

a. Find the output and number of iterations
int i=5;
do { System.out.println(--i);
if(i%2==0)
break; } while(true);​

Answers

Answered by codecracker
0

Answer:

o/p : 4 number of iteration: 1

Answered by anindyaadhikari13
1

Question:-

Find the output and the number of iteration for the following.

Solution:-

Given code,

int i=5;

do

{

System.out.println(--i);

if(i%2==0)

break;

} while(true);

As it is a do while loop, it will run at least one time even though the condition is true or false.

After first iteration,

4 is printed(i=4)

Here, we can see that,

i%2=4%2=0

So,

If block will execute.

>> break statement will execute. Loop terminates here.

Output:-

4

Number of iteration=1.

This is the required answer.

Similar questions