Computer Applications
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);
Java
Java Iterative Stmts
ICSE 2015
68 Likes
Answer
The output of the above code is:
a b c d
Working
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. |
Answered By
30 Likes
Related Questions
Give the output of the following program segment. How many times is the loop executed?
for(x=10; x>20;x++) System.out.println(x); System.out.println(x*2);To execute a loop 10 times, which of the following is correct?
- for (int i=11;i<=30;i+=2)
- for (int i=11;i<=30;i+=3)
- for (int i=11;i<20;i++)
- for (int i=11;i<=21;i++)