Problem 1.(20 points) (Passing Strings to the main Method) Suppose you are to develop a program that performs arithmetic operations ( + - * / ) on integers. The program receives an expression in one string argument. The expression consists of an integer followed by an operator and another integer. For example, to add two integers, use this command: java Calculator "2 + 3" //don t forget the double quotation � mark The program will display the following output: 2 + 3 = 5 The expression must be entered in the form of operand1 � operator operand2 . The operands and operator are � separated by exactly one space. The strings passed to the main program are stored in args, which is an array of strings. In this case, we pass the expression as one string. Therefore, the array contains only one element in args and args.length is 1. Here are the steps in the program: Use args.length to determine whether the expression has been
You've reached the end of your free preview.
Want to read all 3 pages?
- Fall '19
- Algebra, Enter key