Java Integer.sum() – Examples
In this tutorial, we will learn about Java Integer.sum() method, and learn how to use this method to find the sum of two integers, with the help of examples.
sum(int a, int b)
Integer.sum(a, b) adds two integers a
and b
together as per the Arithmetic addition ( + ) operator.
Syntax
The syntax of sum() method with the two integers as parameters is
</>
Copy
Integer.sum(int a, int b)
where
Parameter | Description |
---|---|
a | The first operand for addition. |
b | The second operand for addition. |
Returns
The method returns value of type int.
Example 1 – sum()
In this example, we will take two integers and find their sum using Integer.sum() method.
Java Program
</>
Copy
public class Example {
public static void main(String[] args){
int a = 5;
int b = 8;
int result = Integer.sum(a, b);
System.out.println("Result of sum(" + a + ", " + b + ") = " + result);
}
}
Output
Result of sum(5, 8) = 13
Conclusion
In this Java Tutorial, we have learnt the syntax of Java Integer.sum() method, and also how to use this method with the help of Java example programs.