Give the output of the following snippet:
Charc = 'X';
int n = (int)c + 30;
System.out.println((char)n);
Answers
Answered by
4
Required Answer:-
Correct Cσde:
char c = 'X';
int n = (int)c + 30;
System.out.println((char)n);
To Find:
- Output (Java).
Solution:
Here,
>> c = 'X'
>> (int)c converts the character to integer which gives the ASCII value of the character.
>> ASCII value of 'X' is - 88.
Therefore,
>> n = (int)c + 30
>> n = 88 + 30
>> n = 118
→ Now, (char)n displays the character whose ASCII value is 118 i.e., - 'v'
→ So, output is - 'v'.
Output:
>> v
ASCII Table Characters: (0 - 127):
→ Refer to the attachment.
Attachments:
Similar questions