This is a Java Program to Illustrate the Use of Arithmetic Operators.

Enter two integers as input. After that we use switch case to choose from different arithmetic operations like addition, subtraction, multiplication, division and modulus to get the desired output.

Here is the source code of the Java Program to Illustrate the Use of Arithmetic Operators. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.

import java.util.Scanner;

public class Arithmetic_Operators

`{`

public static void main(String args[])

`{`

Scanner s = new Scanner(System.in);

while(true)

`{`

System.out.println("");

System.out.println("Enter the two numbers to perform operations ");

System.out.print("Enter the first number : ");

int x = s.nextInt();

System.out.print("Enter the second number : ");

int y = s.nextInt();

System.out.println("Choose the operation you want to perform ");

System.out.println("Choose 1 for ADDITION");

System.out.println("Choose 2 for SUBTRACTION");

System.out.println("Choose 3 for MULTIPLICATION");

System.out.println("Choose 4 for DIVISION");

System.out.println("Choose 5 for MODULUS");

System.out.println("Choose 6 for EXIT");

int n = s.nextInt();

switch(n)

`{`

case 1:

int add;

add = x + y;

System.out.println("Result : "+add);

break;

case 2:

int sub;

sub = x - y;

System.out.println("Result : "+sub);

break;

case 3:

int mul;

mul = x * y;

System.out.println("Result : "+mul);

break;

case 4:

float div;

div = (float) x / y;

System.out.print("Result : "+div);

break;

case 5:

int mod;

mod = x % y;

System.out.println("Result : "+mod);

break;

case 6:

System.exit(0);

`}`

`}`

`}`

`}`

Output:

$ javac Arithmetic_Operators.java $ java Arithmetic_Operators Enter the two numbers to perform operations Enter the first number : 12 Enter the second number : 45 Choose the operation you want to perform Choose 1 for ADDITION Choose 2 for SUBTRACTION Choose 3 for MULTIPLICATION Choose 4 for DIVISION Choose 5 for MODULUS Choose 6 for EXIT 1 Result : 57 Enter the two numbers to perform operations Enter the first number : 56 Enter the second number : 42 Choose the operation you want to perform Choose 1 for ADDITION Choose 2 for SUBTRACTION Choose 3 for MULTIPLICATION Choose 4 for DIVISION Choose 5 for MODULUS Choose 6 for EXIT 3 Result : 2352 Enter the two numbers to perform operations Enter the first number : 45 Enter the second number : 56 Choose the operation you want to perform Choose 1 for ADDITION Choose 2 for SUBTRACTION Choose 3 for MULTIPLICATION Choose 4 for DIVISION Choose 5 for MODULUS Choose 6 for EXIT 6

**Sanfoundry Global Education & Learning Series – 1000 Java Programs.**

Here’s the list of Best Reference Books in Java Programming, Data Structures and Algorithms.