本文介紹了為什么 int j = 012 給出輸出 10?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
在我的實際項目中偶然發(fā)生的這里是我修改后的小程序.
In my actual project It happened accidentally here is my modified small program.
我不明白為什么它會輸出 10?
I can't figure out why it is giving output 10?
public class Int
{
public static void main(String args[])
{
int j=012;//accidentaly i put zero
System.out.println(j);// prints 10??
}
}
在那之后,我放了兩個零,仍然給出輸出 10.
After that, I put two zeros still giving output 10.
然后我將 012 更改為 0123,現(xiàn)在輸出 83?
Then I change 012 to 0123 and now it is giving output 83?
誰能解釋一下原因?
推薦答案
比我把 012 改成 0123 現(xiàn)在輸出 83 嗎?
Than I change 012 to 0123 and now it is giving output 83?
因為,它被視為八進(jìn)制基數(shù) (8),因為該數(shù)字的前導(dǎo)是 0.所以,它對應(yīng)的十進(jìn)制值為10.
Because, it's taken as octal base (8), since that numeral have 0 in leading. So, it's corresponding decimal value is 10.
012:
(2 * 8 ^ 0) + (1 * 8 ^ 1) = 10
0123:
(3 * 8 ^ 0) + (2 * 8 ^ 1) + (1 * 8 ^ 2) = 83
這篇關(guān)于為什么 int j = 012 給出輸出 10?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!