gpt4 book ai didi

java - 值如何动态变化

转载 作者:行者123 更新时间:2023-11-29 07:04:08 27 4
gpt4 key购买 nike

我编译了下面的代码,

import java.lang.*;
public class Test
{
public static void main(String[] args)
{
int x=010;
System.out.println("x(010):="+x);

}
}

编译代码后,我得到了值8,但x的实际值为10,它是如何打印值8的,请大神解释一下原因。

最佳答案

它以 0 开头,所以它是八进制表示法。

实际上,x的值是1*8^1 + 0*8^0 = 8

作为JLS状态:

An octal numeral consists of an ASCII digit 0 followed by one or more of the ASCII digits 0 through 7

OctalNumeral:
0 OctalDigits

关于java - 值如何动态变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21828206/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com