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
Hindi,
5 months ago
Math,
5 months ago
Science,
10 months ago
Social Sciences,
10 months ago
Art,
1 year ago