Java Short compareTo()方法及实例
Short类的 compareTo() 方法是Java中的一个内置方法,用于对两个Short对象进行数字比较。
语法
参数 :该方法接受一个强制性参数 otherShort ,它是要比较的Short对象。
返回类型: 它返回一个 int 值。它返回。
- 如果’otherShort’等于’thisShort’,返回0。
- 正值’thisShort’小于’otherShort’。
- 负值’otherShort’大于’thisShort’。
下面是compareTo()方法在Java中的实现:
例1 :
输出:
例2 :
输出:
例3 :
输出: