Java.lang Package Classes

Java Double - sum() Method



The java.lang.Double.sum() method is used to add two double values together as per the + operator.

Syntax

public static double sum(double a,
                         double b)

Parameters

a Specify the first operand.
b Specify the second operand.

Return Value

Returns the sum of a and b.

Exception

NA.

Example:

In the example below, the java.lang.Double.sum() method is used to add two double values together as per the + operator.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //creating double values
    double x = 5.2;
    double y = 10.2;

    //printing the sum of double values
    System.out.println("x + y = " + Double.sum(x, y));   
  }
}

The output of the above code will be:

x + y = 15.399999999999999

❮ Java.lang - Double