Javatpoint Logo
Javatpoint Logo

Java Integer sum() Method

The sum() method of Java Integer class numerically returns the sum of its arguments specified by a user. This method adds two integers together as per the + operator. It can be overloaded and accepts the arguments in int, double, float and long.

Note: If both arguments of the sum() method is in negative, it will always give the result in negative.

Syntax:

Following is the declaration of sum() method:

Parameter:

DataType Parameter Description Required/Optional
int a Numeric value entered by a user. Required
int b Numeric value entered by a user. Required

Returns:

The sum() method returns the sum of its method arguments which will be specified by a user.

Exceptions:

ArithmeticException: It throws exception when the result overflows an integer value.

Compatibility Version:

Java 1.8 and above

Example 1

Test it Now

Output:

The sum of a and b is = 100

Example 2

Output:

Enter the Two numbers for addtion: 
3435
2865
The sum of a and b is = 6300

Example 3

Test it Now

Output:

The sum of a and b is = -200

Example 4

Output:

First Number: 35.55
Second Number: 75.55
The sum of a and b is = 111.10





Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA