Given two integers a and b, an operator, choices:
+, -, *, /
Calculate a <operator> b
.
For a = 1, b = 2, operator = +, return 3.
For a = 10, b = 20, operator = *, return 200.
For a = 3, b = 2, operator = /, return 1. (not 1.5)
For a = 10, b = 11, operator = -, return -1.
public class Calculator {
/**
* @param a: An integer
* @param operator: A character, +, -, *, /.
* @param b: An integer
* @return: The result
*/
public int calculate(int a, char operator, int b) {
// write your code here
switch(operator){
case '+':
return a+b;
case '*':
return a*b;
case '-':
return a-b;
case '/':
return a/b;
}
return 0;
}
}
描述
给出两个整数 a , b ,以及一个操作符 opeator
+, -, *, /
返回结果 a<operator>b
原文:https://www.cnblogs.com/browselife/p/10646002.html