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.
Following is the declaration of sum() method:
The sum() method returns the sum of its method arguments which will be specified by a user.
ArithmeticException: It throws exception when the result overflows an integer value.
Java 1.8 and above
Example 1Test it Now
The sum of a and b is = 100
Enter the Two numbers for addtion: 3435 2865 The sum of a and b is = 6300
Example 3Test it Now
The sum of a and b is = -200
First Number: 35.55 Second Number: 75.55 The sum of a and b is = 111.10