Java DoubleAdder intValue()方法及示例
java.DoubleAdder.intValue() 是java中的一个内置方法,它在缩小原始转换后将sum()返回为一个 int 。当该类的对象被创建时,其初始值为零。
语法
public int intValue()
参数: 该方法不接受任何参数。
返回值: 该方法在转换为int数据类型后返回该对象所代表的数字值。
下面的程序说明了上述函数。
程序1 :
// Program to demonstrate the intValue() method import java.lang.*;import java.util.concurrent.atomic.DoubleAdder; public class GFG { public static void main(String args[]) { DoubleAdder num = new DoubleAdder(); // add operation on num num.add(11); num.add(10); // intValue operation on variable num num.intValue(); // Print after intValue operation System.out.println("the value after intValue() is: " + num); }}
输出:
the value after intValue() is: 21.0
程序2 :
// Program to demonstrate the intValue() method import java.lang.*;import java.util.concurrent.atomic.DoubleAdder; public class GFG { public static void main(String args[]) { DoubleAdder num = new DoubleAdder(); // add operation on num num.add(11); // intValue operation on variable num num.intValue(); // Print after intValue operation System.out.println("the value after intValue() is: " + num); }}输出:
the value after intValue() is: 11.0
参考资料 : https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/DoubleAdder.html#intValue-
