- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java program to generate a calculator using the switch case
The following program accepts two integer variables, takes an operator regarding the operation. According to the selected operator, the program performs the respective operation and print the result.
Example
import java.util.Scanner; public class ab39_CalculatorUsingSwitch { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter value of 1st number ::"); int a = sc.nextInt(); System.out.println("Enter value of 2nd number ::"); int b = sc.nextInt(); System.out.println("Select operation"); System.out.println("Addition-a: Subtraction-s: Multiplication-m: Division-d: "); char ch = sc.next().charAt(0); switch(ch) { case 'a' : System.out.println("Sum of the given two numbers: "+(a+b)); break; case 's' : System.out.println("Difference between the two numbers: "+(a-b)); break; case 'm' : System.out.println("Product of the two numbers: "+(a*b)); case 'd' : System.out.println("Result of the division: "+(a/b)); break; default : System.out.println("Invalid grade"); } } }
Output
Enter value of 1st number :: 52 Enter value of 2nd number :: 85 Select operation Addition-a: Subtraction-s: Multiplication-m: Division-d: a Sum of the given two numbers: 137
- Related Articles
- Java Program to Make a Simple Calculator Using switch...case
- Golang Program to make a Simple Calculator using Switch Case
- Switch case calculator in JavaScript
- C++ Program to Make a Simple Calculator to Add, Subtract, Multiply or Divide Using switch...case
- Basic calculator program using Java
- Java program to find whether given character is vowel or consonant using switch case
- C program to find the areas of geometrical figures using switch case
- Java Program to create a Calculator
- Write a C program of library management system using switch case
- The String in Switch Case in Java
- String in Switch Case in Java
- Basic calculator program using Python program
- Basic calculator program using Python
- Basic calculator program using C#
- Create a simple calculator using Java Swing

Advertisements