Question: Write a Java program which: (1) Prompts a user to enter student two numbers and symbol for operation such as +, -, *, and /

Write a Java program which: (1) Prompts a user to enter student two numbers and symbol for operation such as +, -, *, and / (use Scanner for input).

(2) Code uses nested if statement or switch to perform the operation on the two numbers

(3) If the provided symbol is valid, displays the input data along with the result of the calculation to the console. Otherwise displays error message

For example, for input: 7 8 + the calculation is addition and the result will be 15

Note 1: To read a single character by Scanner, you can read in as string and then use the first character. For example: scan.next().charAt(0)

Note 2: Be careful you do not have integer division Note 3: If user inputs invalid symbol, print an error message only,

I was able to create the code successfully using splitting, .split... but my instructor is saying there is a way to do it without using splitting, and using scan.next().charAt(0) instead. Is that possible? If so, can you help me please?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!