本文介紹了為什么 int j = 012 給出輸出 10?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
在我的實際項目中偶然發生的這里是我修改后的小程序.
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,現在輸出 83?
Then I change 012 to 0123 and now it is giving output 83?
誰能解釋一下原因?
推薦答案
比我把 012 改成 0123 現在輸出 83 嗎?
Than I change 012 to 0123 and now it is giving output 83?
因為,它被視為八進制基數 (8),因為該數字的前導是 0.所以,它對應的十進制值為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
這篇關于為什么 int j = 012 給出輸出 10?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!