Write a program for an Arithmetic calculator using the switch case menu in JAVA
In the below program, the Switch case menu is used to get user input on the operation.
Video Tutorial for the program for an Arithmetic calculator using the switch case menu in Java:-
program for an Arithmetic calculator using the switch case menu in Java
import java.util.*; public class first{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); System.out.print("Enter the operator (+, - , *, /, %)"); char operator=sc.next().charAt(0); System.out.print("Enter 1st number:"); double first=sc.nextDouble(); System.out.print("Enter the 2nd number:"); double Second=sc.nextDouble(); double result=0; switch(operator){ case'+': result=first+Second; System.out.println("Result ="+result); break; case'-': result=first-Second; System.out.println("Result ="+result); break; case'*': result=first*Second; System.out.println("Result ="+result); break; case'/': result=first/Second; System.out.println("Result ="+result); break; case'%': result=first%Second; System.out.println("Result ="+result); break; default:System.out.println("Enter the correct operator!!!!"); } } }