当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java DoubleAccumulator reset()用法及代码示例


Java.DoubleAccumulator.reset()是Java中的内置方法,该方法重置变量,以保持对标识值的更新。这意味着它仅返回复位值,而没有任何参数。返回类型为int。

用法:

public void reset()

参数:该方法不接受任何参数。


返回值:该方法不返回任何内容。

以下示例程序旨在说明上述方法:

示例1:

// Java program to demonstrate 
// the reset() method 
  
import java.lang.*; 
import java.util.concurrent.atomic.DoubleAccumulator; 
  
public class GFG { 
    public static void main(String args[]) 
    { 
  
        DoubleAccumulator num 
            = new DoubleAccumulator( 
                Double::sum, 0L); 
  
        // accumulate operation on num 
        num.accumulate(2); 
        num.accumulate(10); 
  
        // Print before doubleValue operation 
        System.out.println("DoubleAccumulator before reset: "
                           + num); 
  
        // resets current value 
        num.reset(); 
  
        // Print after reset operation 
        System.out.println("DoubleAccumulator after reset: "
                           + num); 
    } 
}
输出:
DoubleAccumulator before reset: 12.0
DoubleAccumulator after reset: 0.0

示例2:

// Java program to demonstrate 
// the reset() method 
  
import java.lang.*; 
import java.util.concurrent.atomic.DoubleAccumulator; 
  
public class GFG { 
    public static void main(String args[]) 
    { 
  
        DoubleAccumulator num 
            = new DoubleAccumulator( 
                Double::sum, 0L); 
  
        // accumulate operation on num 
        num.accumulate(45); 
        num.accumulate(17); 
  
        // Print before doubleValue operation 
        System.out.println("DoubleAccumulator before reset: "
                           + num); 
  
        // resets current value 
        num.reset(); 
  
        // Print after reset operation 
        System.out.println("DoubleAccumulator after reset: "
                           + num); 
    } 
}
输出:
DoubleAccumulator before reset: 62.0
DoubleAccumulator after reset: 0.0


相关用法


注:本文由纯净天空筛选整理自Twinkl Bajaj大神的英文原创作品 DoubleAccumulator reset() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。