Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created March 11, 2022 01:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/740ec479e8a506f8ca772639201c4639 to your computer and use it in GitHub Desktop.
Save parzibyte/740ec479e8a506f8ca772639201c4639 to your computer and use it in GitHub Desktop.
public class SimpleCalculator {
public static double calculate(double operand1, double operand2, char operator) {
switch (operator) {
case '+':
return operand1 + operand2;
case '-':
return operand1 - operand2;
case '*':
return operand1 * operand2;
case '/':
return operand1 / operand2;
case '%':
return operand1 % operand2;
case '^':
return Math.pow(operand1, operand2);
}
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment