Write the output:
char ch=’F’;
int m=ch;
m=m+2;
System.out.println(m+”\t”+ch);
Answers
Answered by
6
Answer:
72 F
Program:
public class something
{
public static void main(String []args)
{
char ch='F';
int m=ch;
m=m+2;
System.out.println(m+"\t"+ch);
}
}
Output:
72 F
Explanation:
As the character 'F' is stored in the variable ch, On assigning ch to m as an integer, the ASCII value of the character that is stored in the variable ch will be stored in m. As the ASCII value of F is 70, variable m is assigned with the value 70.
As now, the value of m is 70, in the next statemnt, on adding 2 to the value in m, the variable m gets 72 into in's memory.
So, finally, 72 tab space F will be printed as, 72 F.
Please look at the attachment given below to see how the program is compiled.
Cheers!!!
Attachments:
Similar questions
Social Sciences,
4 months ago
Math,
4 months ago
Science,
8 months ago
Social Sciences,
8 months ago
Art,
11 months ago