# Java program to enter two numbers and perform all arithmetic operations

ADVERTISEMENTS

In this article, you will learn how to perform all arithmetic operations of two integer numbers in the Java programming language.

### Example

**Enter any two positive integer numbers:**

5

85

8

**SUM 5 + 8 = 13**

DIFFERENCE 5 - 8 = -3

PRODUCT 5 * 8 = 40

QUOTIENT 5 / 8 = 0.0

MODULUS 5 % 8 = 5DIFFERENCE 5 - 8 = -3

PRODUCT 5 * 8 = 40

QUOTIENT 5 / 8 = 0.0

MODULUS 5 % 8 = 5

You should have the knowledge of the following topics in Java programming to understand this program.

- Java Arithmetic operators
- Java

package**java.util.Scanner** - Java

method**main()** - Java

function**System.out.println()**

There we will perform these arithmetic operations like ` Sum, Difference, Multiplication, Division, and Modulus`.

### Source Code

```
// Java program to enter two numbers and perform all arithmetic operations
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter any two positive integer numbers:");
// Reading data using readLine
int p = in.nextInt();
int q = in.nextInt();
int sum, sub, mul, mod;
float div;
sum = p + q;
sub = p - q;
mul = p * q;
div = p / q;
mod = p % q;
System.out.println("\nSUM " + p + " + " + q + " = " + sum);
System.out.println("DIFFERENCE " + p + " - " + q + " = " + sub);
System.out.println("PRODUCT " + p + " * " + q + " = " + mul);
System.out.println("QUOTIENT " + p + " / " + q + " = " + div);
System.out.println("MODULUS " + p + " % " + q + " = " + mod);
}
}
```

### Output

`Enter any two positive integer numbers:`

5

8

`SUM 5 + 8 = 13`

DIFFERENCE 5 - 8 = -3

PRODUCT 5 * 8 = 40

QUOTIENT 5 / 8 = 0.0

MODULUS 5 % 8 = 5

### Explanation

In this given program, we have taken inputs

and **5**

from the user then we applied arithmetic operations on these integer numbers.**8**

Then this will be returned the output values of this program.