KnowledgeBoat Logo

Output Questions for Class 10 ICSE Computer Applications

Find the output of the following program snippet:


char ch = 'x'; int n = 5;
n = n + (int)ch;
char c = (char)n;
System.out.println((char)((int)c-26));

Java

Java Library Classes

ICSE

70 Likes

Answer

c

Working

As ASCII code of 'x' is 120, so the expession n + (int)ch ⇒ 5 + 120 ⇒ 125. After that, the expression (char)((int)c-26) ⇒ (char)(125 - 26) ⇒ (char)99 ⇒ 'c' as ASCII code of 'c' is 99. So, c is the final output.

Answered By

40 Likes