Java Double intValue()方法及示例
Double类的 intValue() 方法是一个内置的方法,用于返回调用对象在类型转换后指定的int值。
语法:
DoubleObject.intValue()
返回值: 它将DoubleObject的值作为int返回。
以下程序说明了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
