當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。