Arithmetic operations on two numbers in java

Arithmetic operations on two numbers

Program to perform arithmetic operations on two numbers in java

This is a Java Program to Calculate the Sum, Multiplication, Division and Subtraction of Two Numbers.
Enter any two integers as input. Now choose from the given options to perform various operations on given integers. The Java program is successfully compiled and run on a Windows system.

  • We are using the standard formula for adding two numbers z=x+y.
  • We are using the formula for subtraction is z=x-y.
  • The formula for multiplication of two numbers is z=x*y.
  • The standard formula for division of two numbers is z=x/y where y!=0.
importjava.util.Scanner;
public class Programs
{
  public static void main(String args[])
  {
    int first, second, add, subtract, multiply;
    floatdevide;
     Scanner scanner = new Scanner(System.in);
     System.out.print("Enter Two Numbers : ");
   first = scanner.nextInt();
   second = scanner.nextInt();
   add = first + second;
   subtract = first - second;
   multiply = first * second;
   devide = (float) first / second;
System.out.println("Sum = " + add);
System.out.println("Difference = " + subtract);
System.out.println("Multiplication = " + multiply);
System.out.println("Division = " + devide);
  }
}

Program Output:

Enter Two Numbers : 60
5
Sum = 65
Difference = 55
Multiplication = 300
Division = 12

I hope this post helps you to understand Arithmetic operations and its implementation in Java programming language.

Keep coding 🙂

4 thoughts on “Arithmetic operations on two numbers in java”

Leave a Reply

Your email address will not be published. Required fields are marked *