Java中的字符文字? [英] Character literal in Java?

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

问题描述

所以我刚刚开始阅读Java In A Nutshell,在第一章中它指出:

So I just started reading "Java In A Nutshell", and on Chapter One it states that:

要在Java程序中包含字符文字,只需将它放在单引号之间
ie

"To include a character literal in a Java program, simply place it between single quotes" i.e.

char c = 'A'; 

这到底是做什么的?我认为char只接受0到65,535的值。我不明白你怎么能给它分配'A'?

What exactly does this do^? I thought char only took in values 0 - 65,535. I don't understand how you can assign 'A' to it?

您还可以将'B'分配给int吗?

You can also assign 'B' to an int?

int a = 'B'

'a'的输出是66.你在哪里/为什么要使用上面的^操作?

The output for 'a' is 66. Where/why would you use the above^ operation?

如果这是一个愚蠢的问题,我道歉。

I apologise if this is a stupid question.

我的一生都是谎言。

推荐答案

char 实际上是一个整数类型。它存储有问题字符的16位Unicode整数值。

char is actually an integer type. It stores the 16-bit Unicode integer value of the character in question.

您可以查看之类的内容http://asciitable.com 查看不同字符的不同值。

You can look at something like http://asciitable.com to see the different values for different characters.

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

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