Incrementing Char Type In Java

前端 未结 10 1599
鱼传尺愫
鱼传尺愫 2020-12-03 05:08

While practicing Java I randomly came up with this:

class test
{
    public static void main(String arg[])
    {
        char x=\'A\';
        x=x+1;
                


        
10条回答
  •  孤城傲影
    2020-12-03 05:26

    you have to type cast the result after adding using parenthesis like this:

    x='A';
    x = (char) (x+1);
    

    else you will get loose of data error.

提交回复
热议问题