how to make a calculator using switch case in java

/* Create Switch cases */
Scanner sc= new Scanner(System.in);
int firstNum= sc.nextInt();
int secondNum= sc.nextInt();
System.out.println("Enter an operator (+, -, *, /):");
char operator= sc.next().chartAt(0);
double result=0;
switch(operator){
  case "+":
    result+= firstNum+ secondNum;
    break;
  case "-":
    result+= firstNum-secondNum;
    break;
  case "*":
    result+= firstNum*secondNum;
    break;
  case "/":
    result+= firstNum/secondNum;
    break;
}

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
switch case calculator in java scientific calculator in java using switch case Java Program to Make a Simple Calculator Using switch...case switch case java use for calculator java switch case calculator java program for calculator using switch case switch case in java calculator simple calculator program in java using switch case java calculator switch case loop java calculator switch case make a calculator using switch statement in java make calculator using switch case in java calculator in java using switch case in loop calculator in java using switch case calculator program using switch case in java calculator using switch case and do while in java calculator using switch case in java calculator java switch case java calc with switch java calculator we have to create a calculator and take input from the user that which operation perform like addition subtraction multiplication by choosing an operation should be performed using scanner method java we have to create a calculator and take input from the user that which operation perform like addition subtraction multiplication by choosing an operation should be perform using scanccer method java we have to create a calculator and take input from the user that which operation perform like addition subtraction multiplication by choosing an operation should be perform using switch statement in java calculator program in java java switch statement add subtract divide calculator with add subtract methods java Implement Calculator Application with Add, Divide, Multiply and Subtract Methods . make a simple calculator using string calculator java program using switch write a program to create calculator in java must contain 5 methods and two java classes write a program to create calculator in java must contain mfollowing method input vales,add,sub,divide,multiply and having two clases and method overloading write a program to create calculator in java must contain mfollowing method input vales,add,sub,divide,multiply and having to clases to implement these method calculator program in java using switch case create a calculator using switch case in java java simple calculator calculator with switch case in java java operator how to make an calculator java program to display basic calculator using Switch Statement. calculator in java using switch calculator avec switch in java java calculator using switch case Create a simple calculator application which asks a user to enter two numbers and the operation (e.g. +, -, x, etc.) that they’d like to perform on the numbers design a simple calculator using switch components using 2 text fields input design a simple calculator using switch components using 2 text fields design a simple calculator using switch components Java Program to Make Calculator code for calculator in java Create a Calculator class that has following methods: sum, multiply, divide , modulus , sin , cos , tan The user should be able to call these methods without creating an object of Calculator class. program in java how to make a calculator using switch case in java
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source