Computer Science, asked by shagunmishra3244, 8 months ago

write a program to calculate and print the sum , multiplication, division and subtraction of given to number in blueprint.. write for java..
correct answer will get unlimited thanks and follow.
humble request​

Answers

Answered by Yashicaruthvik
2

Answer:

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.

Here is the source code of the Java Program to Calculate the Sum, Multiplication, Division and Subtraction of Two Numbers. 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 Calculate  

{

   public static void main(String[] args)  

   {

       int m, n, opt, add, sub, mul;

       double div;

       Scanner s = new Scanner(System.in);

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

       m = s.nextInt();

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

       n = s.nextInt();

       while(true)

       {

           System.out.println("Enter 1 for addition");

           System.out.println("Enter 2 for subtraction");

           System.out.println("Enter 3 for multiplication");

           System.out.println("Enter 4 for division");

           System.out.println("Enter 5 to Exit");

           opt = s.nextInt();

           switch(opt)

           {

               case 1:

               add = m + n;

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

               break;

 

               case 2:

               sub = m - n;

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

               break;

 

               case 3:

               mul = m * n;

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

               break;

 

               case 4:

               div = (double)m / n;

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

               break;    

 

               case 5:

               System.exit(0);

           }

       }

   }

}

Output:

$ javac Calculate.java

$ java Calculate

 

Enter first number:5

Enter second number:2

Enter 1 for addition

Enter 2 for subtraction

Enter 3 for multiplication

Enter 4 for division

Enter 5 to Exit

4

Result:2.5

Enter 1 for addition

Enter 2 for subtraction

Enter 3 for multiplication

Enter 4 for division

Enter 5 to Exit

3

Result:10

Enter 1 for addition

Enter 2 for subtraction

Enter 3 for multiplication

Enter 4 for division

Enter 5 to Exit

5

Explanation:

Similar questions