Computer Science, asked by Lookatmydab12, 6 months ago

What will be the output of the following code:
char ch;for(int x = 97;x <= 100; x++)
{
ch=(char)x;
System.out.println(ch + “ “);
if(x % 10 == 0)
break;
}

Answers

Answered by Anonymous
10

Answer:

a

b

c

d

Explanation:

We knew that the ASCII value of ' a ' is 97.

Here 97 % 10 gives a remainder 0, which, when calculated, turns out to completely wrong. In actuality, it comes as a remainder 7. On encountering the break statement -:

since the test expression is not true, the statement will not break, which will eventually go into the loop and will continue till 100.

Once x variable reaches 100 (100%10==0),

the break would be encountered and the statement would come out of the loop and get executed.

Similar questions