I coded the following, But the o/p is not the expected ? Someone Guide me?
Question: Write a sample program to declare a hexadecimal integer and covert it into a character using explicit type Conversion?
class hexa
{
public static void main(String ar[])
{
int hex=0xA;
System.out.println(((char)hex));
}
}
please tell me :
Why there is a difference in output
/*code 1*/
int hex = (char)0xA;
System.out.println(hex);
/*code 2*/
int hex = 0xA;
System.out.println((char)hex);
The hex value 0xA (or decimal 10) is “\n” (new line feed char) in ASCII.
Hence the output.
EDIT (thanks to halex for providing the correction in comments: