Computer Science, asked by NishitaPandey, 8 months ago

Write a program to perform four basic mathematical calculations (addition, subtraction, multiplications, and division with remainder and quotient part) with two double data-type variables. You can use Scanner class while taking the inputs. User will enter two double data-type variables and an integer variable during runtime. Two double data-type variables for two numbers and the integer value for the switch case. You should follow the following conditions: choice 1: addition choice 2: subtraction choice 3: multiplication choice 4: division Print your result. Other than 1 to 4 print a message for wrong entry. ​

Answers

Answered by jeromeseejo73
2

Answer:

import java.util.Scanner;

public class calc

{

public static void main(String[] args)

{

int choice;

Scanner sc=new Scanner(System.in);

System.out.print("Enter 1 for addition .\nEnter 2 for subtraction.\n Enter 3 for multiplication.\nEnter 4 for division. ")=

choice=sc.nextInt();

switch(choice)

{

case 1:

      System.out.println("ADDITION");

       System.out.print("ENTER A NUMBER: ")

       double a=sc.nextDouble();

       System.out.print("ENTER A NUMBER: ")

       double b=sc.nextDouble();

       double sum=a+b;

        System.out.println("Sum is :"+sum);

case 2:

      System.out.println("SUBTRACTION");

       System.out.print("ENTER A NUMBER: ")

       double x=sc.nextDouble();

       System.out.print("ENTER A NUMBER: ")

       double y=sc.nextDouble();

       double diff=x-y;

       System.out.println("Difference is :"+diff);  

case 3:

      System.out.println("MULTIPLICATION");

       System.out.print("ENTER A NUMBER: ")

       double p=sc.nextDouble();

       System.out.print("ENTER A NUMBER: ")

       double q=sc.nextDouble();

       double mult=p*q;

        System.out.println("Product is :"+mult);

case 4:

      System.out.println("DIVISION");

       System.out.print("ENTER A NUMBER: ")

       double c=sc.nextDouble();

       System.out.print("ENTER A NUMBER: ")

       double d=sc.nextDouble();

       double quotient=c/d;

        System.out.println("Quotient  is :"+quotient);      

default:

        System.out.println("INVALID CHOICE");

}

}

}

Similar questions