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
103 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
59 Likes
Related Questions
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:
int n = 97; char ch = Character.toUpperCase((char)n); System.out.println(ch + " Great Victory");
Find the output of the following program snippet:
char ch = 'A'; char chr = Character.toLowerCase(ch); int n = (int)chr-32; System.out.println((char)n + "\t" + chr);
Java language uses each primitive data type under a specific packet. Other than a data type, the packet also contains the functions to convert the primitive type into string and vice versa. The computer uses 128 ASCII characters. Each character is assigned a specific numeric code called ASCII code. Java language also has the facility to convert the characters into the ASCII code and vice versa.
Based on the above discussion, answer the following questions:
(a) What is the name given to the packet containing a primitive data type?
(b) What is the function used to convert a string data into integer type?
(c) Name the term used to convert a primitive data into the object of its wrapper class.
(d) What is the syntax to convert a string "24" into integer data type?