Computer Applications
Find the output of the following program snippet:
char c = 'A';
int n = (int) c + 32;
System.out.println((char)n);
Java
Java Library Classes
66 Likes
Answer
a
Working
int n = (int) c + 32 ⇒ 65 + 32 ⇒ 97
So, variable n
get the value of 97. 97 is the ASCII code of small a so casting n
to char, prints a to the console.
Answered By
43 Likes
Related Questions
Find the output of the following program snippet:
String s= "7"; int t =Integer.parseInt(s); t=t+1000; System.out.println(t);
Find the output of the following program snippet:
char c = 'B'; int i = 4; System.out.println(c+i); System.out.println((int)c+i);
Find the output of the following program snippet:
char ch = 'y'; char chr = Character.toUpperCase(ch); int p = (int) chr; System.out.println(chr + "\t" + p);
Find the output of the following program snippet:
char ch = '*'; boolean b = Character.isLetter(ch); System.out.println(b);