Java.lang Package Classes

Java Integer - sum() Method



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

Syntax

public static int sum(int a,
                      int 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.Integer.sum() method is used to add two int values together as per the + operator.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //creating int values
    int x = 5;
    int y = 10;

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

The output of the above code will be:

x + y = 15

❮ Java.lang - Integer