Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Kindly check its syntex its not running properly (Urgent plz) The question was Q

ID: 3609013 • Letter: K

Question

Kindly check its syntex its not running properly (Urgent plz) The question was Question 1. Write a program named GoTooFar in which you declare anarray of five integers
and store five values in the array. Initialize a subscript tozero.Write a try block
in which you access each element of the array, subsequentlyincreasing the subscript
by 1. Create a catch block that catches the eventual
ArrayIndexOutOf BoundsException, and then print to the screen themessage,
“Now you’ve gone too far.” Save the program asGoTooFar.java in the
Chapter.15 folder of your Student Disk. _________________________________________________ /*
Chapter 15: Gone Too Far
Programmer: Rod Magnanao
Group: Learning Team A
Filename: GoTooFar.java
*/

/****************************
*Class: number
*****************************
public class GoTooFar
{
public static void main(String[ ] args)
{
int[] num = new int[5];
num[0] = 12;
num[1] = 25;
num[2] = 9;
num[3] = 33;
num[4] = 5;
try
{
for (int i = 0; i < 11; i++)
System.out.println(num[i] + " ");
}
catch (ArrayIndexOutOfBoundsException exception)
{
System.out.println("Now you've gone too far");
}
System.out.println();
}
} Kindly check its syntex its not running properly (Urgent plz) The question was Question 1. Write a program named GoTooFar in which you declare anarray of five integers
and store five values in the array. Initialize a subscript tozero.Write a try block
in which you access each element of the array, subsequentlyincreasing the subscript
by 1. Create a catch block that catches the eventual
ArrayIndexOutOf BoundsException, and then print to the screen themessage,
“Now you’ve gone too far.” Save the program asGoTooFar.java in the
Chapter.15 folder of your Student Disk. _________________________________________________ /*
Chapter 15: Gone Too Far
Programmer: Rod Magnanao
Group: Learning Team A
Filename: GoTooFar.java
*/

/****************************
*Class: number
*****************************
public class GoTooFar
{
public static void main(String[ ] args)
{
int[] num = new int[5];
num[0] = 12;
num[1] = 25;
num[2] = 9;
num[3] = 33;
num[4] = 5;
try
{
for (int i = 0; i < 11; i++)
System.out.println(num[i] + " ");
}
catch (ArrayIndexOutOfBoundsException exception)
{
System.out.println("Now you've gone too far");
}
System.out.println();
}
}

Explanation / Answer

Dear... The given code is executing fine and an array boundexception occurs catch block executes . The output of the following code is: 12                                                      25                                                        9                                                        33                                                         5                                                         Nowyou've gone too far The exception occured because we declared array num withsize 5 so it can hold only 5 values, so tryingto access 6 locationof array will lead to array out of bound exception. Hope this will helpyou.......