Answers for "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"

0

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;
}
Posted by: Guest on November-15-2020

Code answers related to "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"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language