Problem Statement
A simple calculator accepts the following kinds of strings as input:
- 1) NUM+NUM
- 2) NUM-NUM
- 3) NUM*NUM
- 4) NUM/NUM
Definition
- Class:
- SimpleCalculator
- Method:
- calculate
- Parameters:
- String
- Returns:
- int
- Method signature:
- int calculate(String input)
- (be sure your method is public)
Constraints
- input will contain between 3 and 50 characters inclusive.
- input will have the form <NUM><OP><NUM> where<NUM> is a positive integer between 1 and 10000 inclusive, that may contain leading zeros and <OP> is one of (quotes for clarity) '+','*','-', or '/'.
- input will not contain any spaces.
Examples
"5/3"
Returns: 1
Remember integer division is used, so results are truncated."15*3"
Returns: 45
"1-10000"
Returns: -9999
Negative results are allowed."17+18"
Returns: 35
"0000000000000018/00000000000000000009"
Returns: 2
The long way of writing 18/9.