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
67 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
Define a class to accept a number from user and check if it is an EvenPal number or not.
(The number is said to be EvenPal number when number is palindrome number (a number is palindrome if it is equal to its reverse) and sum of its digits is an even number.)
Example: 121 – is a palindrome number
Sum of the digits – 1+2+1 = 4 which is an even numberDefine a class to accept a number and check whether it is a SUPERSPY number or not. A number is called SUPERSPY if the sum of the digits equals the number of the digits.
Example1:
Input: 1021 output: SUPERSPY number [SUM OF THE DIGITS = 1+0+2+1 = 4, NUMBER OF DIGITS = 4 ]Example2:
Input: 125 output: Not an SUPERSPY number [1+2+5 is not equal to 3]Rewrite the following do while program segment using for:
x = 10; y = 20; do { x++; y++; } while (x<=20); System.out.println(x * y );How many times will the following loop execute? Write the output of the code:
int x=10; while (true){ System.out.println(x++ * 2); if(x%3==0) break; }