Question: In Java. 10. (15 pts) An nputuismatchExsentian is thrown by a Scanner to indicate that the token retrieved does not match the patten for the

 In Java. 10. (15 pts) "An nputuismatchExsentian is thrown by a

In Java.

10. (15 pts) "An nputuismatchExsentian is thrown by a Scanner to indicate that the token retrieved does not match the patten for the expected type, or that the token is out of range for the expected type. For example, if you use the nextRaubla to read a token that is not of the type double. Write a program that prompts the user to enter a mathematical formula (e.g., 4.3 5.1) and then displays the result. Your program should prompt the user to try again if the input has an invalid number or invalid operator (i.e., valid operators are: /, and ). Assume the user enters spaces between the operands and the operator. Read the numbers using the scanner's nextDouble method, and the operator using the next method. Hints Use a while loop that will keep prompting the user for input as long as it is invalid. Use a try-catch statement to check for the numbers' validity Use a selection statement (e.g., if, switch, etc.) to check for the operator's validity Sample run Enter a simple mathematical formula: 9.1 plus 4.2 Invalid Operator. Try again. 9.1x 4.2 Invalid number format. Try again. 9.1 +4.2 Result: 13.3

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!