Double类的intValue()方法是一种内置方法,用于在类型转换后返回调用对象指定为int的值。
用法:
DoubleObject.intValue()
返回值:它以Double形式返回DoubleObject的值。
以下程序说明了Java中的intValue()方法:
示例1:
// Java code to demonstrate
// Double intValue() method
class GFG {
public static void main(String[] args)
{
// Double value
Double a = 17.47;
// wrapping the Double value
// in the wrapper class Double
Double b = new Double(a);
// intValue of the Double Object
int output = b.intValue();
// printing the output
System.out.println("Int value of "
+ b + " is : " + output);
}
}
输出:
Int value of 17.47 is : 17
示例2:
// Java code to demonstrate
// Double intValue() method
class GFG {
public static void main(String[] args)
{
String value = "54.1";
// wrapping the Double value
// in the wrapper class Double
Double b = new Double(value);
// intValue of the Double Object
int output = b.intValue();
// printing the output
System.out.println("Int value of "
+ b + " is : " + output);
}
}
输出:
Int value of 54.1 is : 54