Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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.
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.classStep 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