Answered step by step
Verified Expert Solution
Link Copied!

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

image

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Java An Introduction To Problem Solving And Programming

Authors: Walter Savitch

8th Edition

0134462033, 978-0134462035

More Books

Students also viewed these Programming questions