Write a java program that repeatedly lets the user enter an array of values. Onc
ID: 3541530 • Letter: W
Question
Write a java program that repeatedly lets the user enter an array of values. Once the array is entered, the program asks the user whether the values should be summed or multiplied. This program should let the user choose any valid array size. That is, any positive number can be the size. While the prompt in the Sample Runs says that a size of -1 will quit the program, you should automatically assume any non-positive size means the user wants to quit. You don't have to handle invalid input in an elegant way. In particular, if the user enters letters when you are expecting numbers, it's acceptable for your program to crash.
Sample run #1
Welcome to the Array Calculator Program!
Enter the size of the array (-1 to quit): 4
Enter 4 integers: 2 3 4 5
Multiply or add (*, +) ? : +
The sum of the array values is 14
Enter the size of the array (-1 to quit): 3
Enter 3 integers: 7 20 -2
Multiply or add (*, +) ? : *
The product of the array values is -280Enter the size of the array (-1 to quit): -1
Goodbye!
Sample run #2
Welcome to the Array Calculator Program!
Enter the size of the array (-1 to quit): *
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:840)
at java.util.Scanner.next(Scanner.java:1461)
at java.util.Scanner.nextInt(Scanner.java:2091)
at java.util.Scanner.nextInt(Scanner.java:2050)
at Calculator.main(Calculator.java:13)
Explanation / Answer
https://www.dropbox.com/s/0k7fz45vj2wu8k2/ArrayCalculator.java
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.