Incrementing Char Type In Java

前端 未结 10 1592
鱼传尺愫
鱼传尺愫 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:24

    A char in Java is just an integer number, so it's ok to increment/decrement it. Each char number has a corresponding value, an interpretation of it as a character, by virtue of a conversion table: be it the ASCII encoding, or the UTF-8 encoding, etc.

    Come to think of it, every data in a computer - images, music, programs, etc. are just numbers. A simple character is no exception, it's encoded or codified as a number, too.

提交回复
热议问题