Ternary operator casts integer

前端 未结 3 1353
情歌与酒
情歌与酒 2020-12-21 15:25

Please have a look into the below code

int a =10;
int b =20;
System.out.println((a>b)?\'a\':65);//A
System.out.println((a>b)?a:65);//65
System.out.prin         


        
3条回答
  •  暖寄归人
    2020-12-21 16:26

    When your line System.out.println((a>b)?'a':65);//A is executed, JVM sees that your condition is false, so it will output 65. Now, you have provided 'a' as first possible output, 65 will be converted to char and 'A' will be returned, which has ASCII value 65.

提交回复
热议问题