Simple Calculator Program in Java using switch/case

In this program, you'll learn to make a Simple Calculator using a switch/case in Java. This calculator would be able to add, subtract, multiply and divide two numbers.


This program is a simple calculator. It uses a switch/case statement to calculate the calculation and print the result. The program can be enhanced by adding more features like memory, check digit, etc.


This program is written in the Java programming language. The program starts by declaring the main method. The main method is where the execution of a Java program begins.


This program uses the Scanner class to read input from the user. The Scanner class is used to read values and convert them to a primitive data type. The program uses the System.out.println() method to print out the values that are read from the user. Program to find the average of a list of numbers using Scanner class.


To understand this example, you should have knowledge of the following Java programming topics:

  • Java Switch Statement
  • Java Scanner Class


Simple Calculator in Java | Java Program to Make a Simple Calculator Using switch/case



Simple Java Calculator Program with Switch/Case Statement


package calculator;
import java.util.Scanner;
public class NewClass {
Scanner shazo = new Scanner(System.in);
double a,b;
double c;
public void main_menu(){
System.out.println("Press 1 for addition");
System.out.println("Press 2 for substraction");
System.out.println("Press 3 for division");
System.out.println("Press 4 for multplication");
System.out.println("Press 5 for percentage");
System.out.println("========================");
System.out.println("========================");
System.out.print("what you want to do :");
int x = shazo.nextInt();
switch (x){
case 1:
    System.out.println("Enter first number");
    a = shazo.nextInt();
    System.out.println("Enter Second number");
    b = shazo.nextInt();
    c = a +b;
    System.out.println("sum is :"+c);
    break;
case 2:
    System.out.println("Enter first number");
    a = shazo.nextInt();
    System.out.println("Enter Second number");
    b = shazo.nextInt();
    c = a -b;
    System.out.println("substract is :"+c);
    break;
case 3:
    System.out.println("Enter first number");
    a = shazo.nextInt();
    System.out.println("Enter Second number");
    b = shazo.nextInt();
    c = a /b;
    System.out.println("division is :"+c);
    break;
case 4:
    System.out.println("Enter first number");
    a = shazo.nextInt();
    System.out.println("Enter Second number");
    b = shazo.nextInt();
    c = a * b;
    System.out.println("multiplication is :"+c);
    break;
case 5:
    System.out.println("Enter obtain marks");
    a = shazo.nextInt();
    System.out.println("Enter total marks");
    b = shazo.nextInt();
    c = a*100/b;
    System.out.println("percentage is :"+c+"%");
    break;

default :
        System.out.println("Enter correct NO.!!");
     }
}

public static void main(String[] args) {
    NewClass asad = new NewClass();
    asad.main_menu();
    }
}

General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog General Knowledge Blog

Post a Comment

Previous Post Next Post