English, asked by divyapal2170, 9 months ago

Write a java program that takes three inputs from the user as one operator and 2 numbers. it performs calculation based on numbers and operator entered. display the output in below format: enter operator(either + , - ,* or / ) : *
enter number 1 and number 2 : 4
5
multiplication of two number is 20.

Answers

Answered by Anonymous
1

Answer:

import java.util.Scanner;

public class Calculator

{

public static void main(String[] args)

double result = 0.0;

int a,b,n;

 Scanner sc=new Scanner(System.in);

 System.out.println("Enter your choice : ");

 System.out.println("1. ADDITION "+"");

 System.out.println("2. SUBTRACTION "-"");

 System.out.println("3. MULTIPLICATION "×"

");

 System.out.println("4. DIVISION "÷"");

 n=sc.nextInt(); 

 System.out.println("ENTER FIRST NUMBER

");

 a=sc.nextInt();

 System.out.println("ENTER SECOND

NUMBER ");

 b=sc.nextInt();

if(n == 1)

{

result = a+b;

}

if(n == 2)

{

result = a-b;

}

if(n == 3)

{

result = a×b;

}

if(n == 4)

{

result = a/b;

}

System.out.println(" Result = "+ result);

}

}

Similar questions