SHARE
TWEET

Untitled

advictoriam Jan 15th, 2019 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Numbers
  2. {
  3.    /**
  4.       Combines two numbers with a given operator.
  5.       @param op one of "+", "-", "*", "/", or "^" (for power)
  6.       @param first the first argument
  7.       @param second the second argument
  8.       @return the result of evaluating the operator with the arguments
  9.    */
  10.    public static double evaluate(String op, double first, double second)
  11.    {
  12.       switch(op)
  13.       {
  14.       case "+":
  15.          return first + second;
  16.       case "-":
  17.          return first - second;
  18.       case "*":
  19.          return first * second;
  20.       case "/":
  21.          return first / second;
  22.       case "^":
  23.          return Math.pow(first, second);
  24.       }
  25.       return -1.0;
  26.    }
  27. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top