Question: Write a program named Lab 2 8 B that does the following. a . Create an array of 5 integers. b . Place the following
Write a program named LabB that does the following.
a Create an array of integers.
b Place the following statements into a try block.
i Ask the user to input a filename
ii Set up the input file
iii. Using a while hasNext loop read the values from the input file into the array
iv Print the array values on one line with spaces and total them as you read them
in
v Calculate the average after the loop and print it
c Write the catch block to catch an ArrayIndexOutOfBoundsException. Inside it print the
error message and stop the program.
d Write a second catch block for an InputMismatchException. Print the error message
yourself and stop the program.
e To test your program, run it times with these requirements.
i Enter InputBtxt; this should result in the error message for
"ArrayOutOfBounds"
ii Enter InputBtxt for the text file name; this should result in the error
message for "InputMismatch".
iii. Enter InputBtxt for the text file name; the program should run correctly.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
