Problem 1.(20 points)(Passing Strings to the main Method) Suppose .docx - Problem 1(20 points(Passing Strings to the main Method Suppose you are to

Problem 1.(20 points)(Passing Strings to the main Method) Suppose .docx

This preview shows page 1 - 3 out of 3 pages.

Image of page 1
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[0] and args.length is 1. Here are the steps in the program: Use args.length to determine whether the expression has been
Image of page 2
Image of page 3

You've reached the end of your free preview.

Want to read all 3 pages?

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture