do loop based output writing – Computer Sir Ki Class

Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  

Login
[lwa]



Exam Questions-ICSE2015-03H #JAVA#4275    siteicon   siteicon  

Problem Statement - do loop based output writing

Write the output of the following code segment:

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

 

Solution

TC++ #4275

The output would be
a b c d

Notes

  • Since the code has an integer  value type casted as character so in first essential entry do-while loop of it will print character a followed by a single space, then the loop continues till the value reaches 100 which is ascii code of d, so all the characters from a to d are printed with a following space.


Share

sunmitra| Created: 5-Apr-2018 | Updated: 16-Apr-2019|ICSE2015









Back