Why is '\117' a valid character literal in Java? [duplicate]

一世执手 提交于 2019-12-10 12:30:22

问题


I've seen this char defined as char ch = '\117'

What kind of representation is '\117' in?

I know escaped-sequence is '\n', for instance, or unicode is `\udddd', where d is a single hex digit, but I've never seen such thing as '\117' in my entire life! Surprisingly, it does compile! (And the output is O)


回答1:


This is the octal representation for ascii. You can see lots more values of it here: http://donsnotes.com/tech/charsets/ascii.html




回答2:


It's in octal, a holdover from C/C++.




回答3:


That is because its the Octal representation of captial O character.

If you try to print your char ch='\117'; , you will see that it prints O.




回答4:


It's a Octal value for character "O", when I did system.out.println(..) I got this output:

char ch = '\117';
System.out.println("Char is: " + ch);

Output:

Char is : O


来源:https://stackoverflow.com/questions/14950593/why-is-117-a-valid-character-literal-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!