Java Development Basics-Practice ③ Advanced Programming-
problem
Let's make a calculator that only adds and subtracts.
Numbers and operators are passed as arguments.
conditions
- Let's have as many arguments as you like
- Only "+" and "-" operators are used. If any other number is entered, "the operator is invalid" is returned.
- Only Arabic numerals are allowed for numbers
- Prevent the program from terminating with an error
Roughly, I expect the following results.
- Other values may be entered, so consider a test case to avoid errors.
Input value |
result |
1 + 2 + 3 |
The calculation result is 6 |
1 + 2 - 3 |
The calculation result is 0 |
1 plus 2 plus 3 |
Operator is invalid |