Predict the output of the following code snippet:

ICSE Class 10 Computer Applications PYQ · 2025 Specimen · Section A

2(vii)1 Mark · 2025 · Section A · 2025 Specimen

Predict the output of the following code snippet:

char ch='B',
char chr=Character.toLowerCase(ch); 
int n=(int)chr-10; 
System.out.println((char)n+"\t"+chr);
Show SolutionHide Solution↓
X	b

Step-by-Step Execution:

char ch = 'B';

  • ch is assigned the character 'B'.

char chr = Character.toLowerCase(ch);

  • Character.toLowerCase(ch) converts 'B' to its lowercase equivalent 'b'.
  • chr = 'b'.

int n = (int) chr - 10;

  • (int) chr converts the character 'b' to its ASCII value.
  • ASCII value of 'b' is 98.
  • n = 98 - 10 = 88.

System.out.println((char) n + "\t" + chr);

  • (char) n: Converts the integer 88 back to a character.
    • ASCII value 88 corresponds to the character 'X'.
  • + "\t" + adds a tab space between the characters.
  • chr: The value of chr is 'b'.
← Previous questionNext question →

Browse the free Computer Applications sample bank