Question: I am having trouble with my java homework. When I tried to compile it and run it using the Terminal application on my MAC, it

I am having trouble with my java homework. When I tried to compile it and run it using the Terminal application on my MAC, it is saying this: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at IntArrayTest.main(IntArrayTest.java:30). I understand that it is saying that there is a problem in line 30 of my source code, but I do not understand what is the problem. I am attaching a picture to show you what I got. I also showed where is line 30. Please help me. I am having trouble with my java homework. When I tried to

IntArrayTest J Int ArrayTest java No Selection public class IntArrayTest attributes private final int SIZE 15 private int A[] new int SIZE The array needs to be initialized private int currentPosition 0; methods public IntArrayTest //System.out.println length A length for currentPosition A.length: currentPosition AlcurrentPosition] 10 current Position) 5 //return: do not place a return here public int search(int key) for int i 0: i A length; i System.out.println(Ali)); if (A[i] mm key) return i; //for return -1 /ot found //search main public static void nain (String args[]) Int Array ar a new IntArrayTest Test int key Integer.parsclnt targs //line 30 the value to search for, input from command line System.out.println("My name is XYZ. int result arr .search (key System result result if result -1) System out.println(key is not in the array else System out.println(key is stored at position result //rain IntArray Test class Desktop -bash -104x50 Last Login Mon Jun 12 14:43:48 on console cd Desktop/ i r:Desktop javac IntArrayTest.java acBook Air Desktop java IntArrayTest n in thread main" java. tang. ArrayIndex0utofBoundsException: 0 cept. at IntArray Test. Test ava:30 IntArrayTest.class

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!