Question
Write a program that declares an array of numbers. The array should have the following numbers in it 7,8,9,10,11. Do this in the main method.
Write a program that declares an array of numbers. The array should have the following numbers in it 7,8,9,10,11. Do this in the main method. Make a method called printArray. This will return nothing, so it should be a void type method. Then make a for loop that looks like this for(int i=0; i < 10; i++). Iterate through the array of numbers and print out each number with println(). If you do this properly you should get an error when your program runs. You will generate an array index out of bounds exception. You need to add exception handling to your program so that you can catch the index out of bounds exception and a normal exception. When you catch the exception just print you caught it. You also need to have a finally section in your try/catch block.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started