Java int division令我困惑 [英] Java int division confusing me
本文介绍了Java int division令我困惑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在进行非常简单的int划分,我得到了奇怪的结果。
I am doing very simple int division and I am getting odd results.
此代码打印 2
as预期:
This code prints 2
as expected:
public static void main(String[] args) {
int i = 200;
int hundNum = i / 100;
System.out.println(hundNum);
}
此代码打印 1
as 不预期:
This code prints 1
as not expected:
public static void main(String[] args) {
int i = 0200;
int hundNum = i / 100;
System.out.println(hundNum);
}
这里发生了什么?
(Windows XP Pro,在Eclipse 3.4.1中运行的Java 1.6)
推荐答案
值 0200
是八进制(基数为8)常量。它等于128(十进制)。
The value 0200
is an octal (base 8) constant. It is equal to 128 (decimal).
八进制数字由ASCII数字0后跟一个或多个ASCII数字0到7组成,可以表示正整数,零或负整数。
An octal numeral consists of an ASCII digit 0 followed by one or more of the ASCII digits 0 through 7 and can represent a positive, zero, or negative integer.
这篇关于Java int division令我困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文