为什么0010在Java中的数组中给出不同的结果 [英] Why 0010 give different result in array in java

查看:87
本文介绍了为什么0010在Java中的数组中给出不同的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在数组输出中的数字值变得不同之前放置00或0.

If I placed 00 or 0 before digits values in array output become different.

 int arr[][]=new int[3][2];
    arr[0][0]=00;
    arr[0][1]=01;
    arr[1][0]=10;
    arr[1][1]=0011;
    arr[2][0]=0020;
    arr[2][1]=21;
    for(int a[]: arr){
        for(int c : a){
            System.out.println(c);
        }

    }

输出为: 0 1个 10 9 16 21

Output is : 0 1 10 9 16 21

推荐答案

以零开头的数字被视为 Octal .

A number with a leading zero is treated as Octal.

您的0011是八进制的8 + 1 = 900202 * 8 = 16.

Your 0011 is octal 8 + 1 = 9, 0020 is 2 * 8 = 16.

请注意,您的0001也在八进制中进行解释,但它们恰好与十进制对应值相同.

Note that your 00 and 01 are also being interpreted in Octal but they just happen to be the same value as their decimal counterparts.

这篇关于为什么0010在Java中的数组中给出不同的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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