compareTo的用法
使用Integer实例的compareTo方法来比较两个Integer的值,
- 如果返回值为0 说明两个数相等
- 如果返回值为1 说明第一个数大于第二个数
- 如果返回值为-1 说明第一个值小于第二个数
private static void compares(Integer i, Integer j) {
System.out.println(i.compareTo(j));
if(i.compareTo(j) == 0 ){
System.out.println(“两个数相等”);
}else if(i.compareTo(j) > 0){
System.out.println(“第一个数大于第二个数”);
}else if(i.compareTo(j) < 0 ){
System.out.println(“第一个数小于第二个数”);
}
}