在Java中增加字符类型 [英] Incrementing Char Type In Java

查看:161
本文介绍了在Java中增加字符类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在练习Java时我随机地想出了这个:

While practicing Java I randomly came up with this:

class test
{
    public static void main(String arg[])
    {
        char x='A';
        x=x+1;
        System.out.println(x);
    }
}

我以为会抛出一个错误,在数学中向字母 A 添加数值 1 ,但以下程序运行正确,并打印

I thought it will throw an error because we can't add the numeric value 1 to the letter A in mathematics, but the following program runs correctly and prints

B 

推荐答案

在Java中, char 数字类型。当您向 char 添加 1 时,您会进入下一个unicode代码点 。在'A'的情况下,下一个代码点是'B'

In Java, char is a numeric type. When you add 1 to a char, you get to the next unicode code point. In case of 'A', the next code point is 'B'.

这篇关于在Java中增加字符类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆