Home / Questions / Write the output of the following program code: char ch ; int x=97; do { ch=(char)x; System.out.print(ch + " " ); if(x%10 == 0) break; ++x; } while(x
Explanatory Question

Write the output of the following program code:

char ch ;
int x=97;
do
{
    ch=(char)x;
    System.out.print(ch + " " );
    if(x%10 == 0)
    break;
    ++x;
} while(x<=100);

👁 72 Views
📘 Detailed Answer
🕒 Easy to Read
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.

Answer with Explanation


char ch ;
int x=97;
do
{
    ch=(char)x;
    System.out.print(ch + " " );
    if(x%10 == 0)
    break;
    ++x;
} while(x<=100);

The output of the above code is:


a b c d

Explanation

The below table shows the dry run of the program:

x ch Output Remarks
97 a a 1st Iteration
98 b a b 2nd Iteration
99 c a b c 3rd Iteration
100 d a b c d 4th Iteration — As x%10 becomes true, break statement is executed and exists the loop.