Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this question, you will write a Java program that calculates special arithmetic expressions. These expressions start with either + or *. Then, 3
In this question, you will write a Java program that calculates special arithmetic expressions. These expressions start with either + or *. Then, 3 positive integer numbers follow them separated by commas and enclosed in parenthesis. Depending on the operation given at the start of the expression, either you sum up or multiply all the numbers inside the parenthesis. For example, +(2,3,4) is a special arithmetic expression and its result is 9 (2+3+4=9). Here are two other examples: the expression +(30,1,22) is equal to 53 and the expression *(12,2,2) is equal to 48. Your program must ask the user to enter the special arithmetic expression and output its result. You can use nextLine() method of the Scanner object to read the expression as input. You can use the method Integer.parseInt() in order to convert a string representation of an integer to its integer value. Here are some sample runs: Enter an expression: +(2,3,4) The result is 9. Enter an expression:* (10,21,2) The result is 420. Enter an expression: +(2,31,1002) The result is 1035. Enter an expression: * (2,3,2) The result is 12.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started