Apr 2, 2021

Java program to print addition, subtraction, multiplication and division of given two numbers

EX: Write a java program which perform addition, subtraction, multiplication and division. How to write a java program which prints addition, subtraction, multiplication and division of  two numbers. java program which perform addition, subtraction, multiplication and division.


Program:

import java.util.Scanner;

public class ASMD {

    public static void main(String[] args) {

        int num1;
        int num2;
        int add, sub, mult;
        float div;

        Scanner sc = new Scanner(System.in);

        System.out.println("Enter the number1: ");
        num1 = sc.nextInt();
        System.out.println("Enter the number2: ");
        num2 = sc.nextInt();

        add = num1 + num2;
        sub = num1 - num2;
        mult = num1 * num2;
        div = num1 / num2;

        System.out.println("Addition of given two numbers is : " + add);
        System.out.println("Subtraction of given two numbers is : " + sub);
        System.out.println("Multiplication of given two numbers is : " + mult);
        System.out.println("Division of given two numbers is : " + div);
    }
}
Above java code shows the following output:

Enter the number1: 57
Enter the number2: 33

Addition of given two numbers is : 90
Subtraction of given two numbers is : 24
Multiplication of given two numbers is : 1881
Division of given two numbers is : 1.0

Share This:    Facebook Twitter

0 comments:

Post a Comment

If you have any doubts, please discuss here...