整数值比较 [英] Integer value comparison
问题描述
我是一个新手Java编码器,我只是读取一个整数类的变量,可以在API中描述三种不同的方式。我有以下代码:
I'm a newbie Java coder and I just read a variable of an integer class can be described three different ways in the API. I have the following code:
if (count.compareTo(0)) {
System.out.println(out_table);
count++;
}
这是一个循环,只输出 out_table
。
我的目标是弄清楚如何查看整数中的值是否计数> 0
。
This is inside a loop and just outputs out_table
.
My goal is to figure out how to see if the value in integer count > 0
.
我意识到 count.compare(0)
是正确的方法吗?还是 count.equals(0)
?
I realize the count.compare(0)
is the correct way? or is it count.equals(0)
?
我知道 count == 0
不正确。这是正确的吗?是否有一个值比较运算符,它只是 count = 0
?
I know the count == 0
is incorrect. Is this right? Is there a value comparison operator where its just count=0
?
推荐答案
整数是自动装箱的,所以你可以这样做
Integers are autounboxed, so you can just do
if (count > 0) {
....
}
这篇关于整数值比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!