Computer Science, asked by prasannasagi2002, 7 months ago

Write a java programm Sum Of Two Numbers(static method)

Answers

Answered by nknandha
1

Explanation:

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:

public static int sum(int a, int b)

public static long sum(long a, long b)

public static float sum(float a, float b)

public static double sum(double a, double b)

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

public class IntegerSumExample1 {

public static void main(String[] args) {

int a = 65;

int b = 35;

// It will return the sum of a and b.

System.out.println("The sum of a and b is = " + Integer.sum(a, b));

}

}

Test it Now

Output:

The sum of a and b is = 100

Example 2

import java.util.Scanner;

public class IntegerSumExample2 {

public static void main(String[] args) {

System.out.println("Enter the Two numbers for addtion: ");

Scanner readInput = new Scanner(System.in);

int a = readInput.nextInt();

int b = readInput.nextInt();

readInput.close();

// It will return the sum of a and b.

System.out.println("The sum of a and b is = " + Integer.sum(a, b));

}

}

Output:

Enter the Two numbers for addtion:

3435

2865

The sum of a and b is = 6300

Example 3

public class IntegerSumExample3 {

public static void main(String[] args) {

int a = -65;

int b = -135;

// It will return the sum of a and b.

System.out.println("The sum of a and b is = " + Integer.sum(a, b));

}

}

Test it Now

Output:

The sum of a and b is = -200

Example 4

import java.util.Scanner;

public class IntegerSumExample4 {

public static void main(String[] args) {

Scanner readInput = new Scanner(System.in);

System.out.print("First Number: ");

float a = readInput.nextFloat();

System.out.print("Second Number: ");

float b = readInput.nextFloat();

readInput.close();

// It will return the sum of a and b.

System.out.print("The sum of a and b is = " + Float.sum(a, b));

}

}

Output:

First Number: 35.55

Second Number: 75.55

The sum of a and b is = 111.10

← prevnext →

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials

IoT Tutorial

IoT

GraphQL Tutorial

GraphQL

Xampp Tutorial

Xampp

Kivy Tutorial

Kivy

Automation Anywhere Tutorial

A. Anywhere

Ext.js Tutorial

Ext.js

UiPath Tutorial

UiPath

Arduino tutorial

Arduino

Digital Electronics tutorial

Digital E.

Google Adwords tutorial

Adwords

MySQL tutorial

MySQL

Python tutorial

Python

smartsheet

Smartsheet

affiliate marketing

Affiliate M.

Preparation

Aptitude

Aptitude

Logical Reasoning

Reasoning

Verbal Ability

Verbal A.

Interview Questions

Interview

Company Interview Questions

Company

Trending Technologies

Artificial Intelligence Tutorial

Answered by decentbaby70
0

Answer:

class addition

{

public static void main(string arg [])

{

system. out. println(a+"+"+b+"="+c) ;

}

}

Similar questions