Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Numbers
- {
- /**
- Combines two numbers with a given operator.
- @param op one of "+", "-", "*", "/", or "^" (for power)
- @param first the first argument
- @param second the second argument
- @return the result of evaluating the operator with the arguments
- */
- public static double evaluate(String op, double first, double second)
- {
- switch(op)
- {
- case "+":
- return first + second;
- case "-":
- return first - second;
- case "*":
- return first * second;
- case "/":
- return first / second;
- case "^":
- return Math.pow(first, second);
- }
- return -1.0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement