Java Double compare() 方法

2024 年 11 月 10 日 | 阅读 2 分钟

Java Double 类的 compare() 方法用于比较两个指定的 double 值。

语法

参数

两个参数 -

d1 - 要比较的第一个 double 值。

d2 - 要比较的第二个 double 值。

返回值

此方法将返回一个值 -

  • 如果 d1 在数值上等于 d2,则返回零。
  • 如果 d1 在数值上小于 d2,则返回小于零的值。
  • 如果 d1 在数值上大于
  • d2,则返回大于零的值。

示例 1

输出

10.56 is greater.
Difference is= 0.5600000000000005.

示例 2

输出

Error:(13, 26) java: method compare in class java.lang.Double cannot be applied to given types;
  required: double,double
  found: java.lang.Double
  reason: actual and formal argument lists differ in length

示例 3

输出

Enter your Family income
45000
Sorry, You are not eligible for the subsidy