Menu

Simple Calculator in JAVA with switch case

We are going to make a Simple Calculator in JAVA with switch case.This calculator will have four basic arithmetic operations “Addition, Subtraction, Multiplication, and Division“.So, below is the JAVA code for the simple calculator.

Code:

import java.util.Scanner;

class calc
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
System.out.println(” Simple Calculator”);
System.out.println(“Enter the first number:”);
int a=s.nextInt();

System.out.println(“Enter the second number:”);
int b=s.nextInt();

System.out.println(“Choose the operation”);
System.out.println(“1.ADD 2.SUB 3.MUL 4.DIV”);

int result;

int choice=s.nextInt();

switch(choice)
{
case 1:
result=a+b;
System.out.println(“The result is: “+result);
break;

case 2:
result=a-b;
System.out.println(“The result is: “+result);
break;

case 3:
result=a*b;
System.out.println(“The result is: “+result);
break;

case 4:
result=a/b;
System.out.println(“The result is: “+result);
break;

default:
System.out.println(“Error….Wrong Choice”);

}
}
}

 

Read More:  Making Your Own Android Game Easily Using Appsgeyser

 

Output:

Calculator in JAVA with switch case

 

If you have any doubt’s and suggestion, feel free to comment.

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this:
DMCA.com Protection Status