Given:
int myChar = 97; int yourChar = 98; System.out.print((char)myChar + (char)yourChar); int age = 20; System.out.print(" "); System.out.print((float)age);
What is the output?
a
When a char primitive data type is used as an operand to arithmetic operators, its corresponding ASCII value is used in the arithmetic operation.
Though (char)myChar
explicitly casts int variable myChar
to char type,
its value 97 is used in the arithmetic operation.
When literal value 20 is explicitly cast to a float type, it outputs its value as a decimal number, that is, 20.0.