IntArrayTest J Int ArrayTest java No Selection public class IntArrayTest attribu
ID: 3848569 • Letter: I
Question
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 //not 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.classExplanation / Answer
The code is compiled using "javac <filename>.java".
The bytecode file is generated, which is then run using "java <filename> argument1 argument2 argument3........"
The argument is missing while the code is being run, that is the reason it gives an ArrayIndexOutOfBoundException.
The argument is not provided and at line 30, an argument at index 0 is asked for.
Run the code as: java Int ArrayTest 39
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.