Answered step by step
Verified Expert Solution
Link Copied!

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. image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL Crash Course A Hands On Introduction To Database Development

Authors: Rick Silva

1st Edition

1718503008, 978-1718503007

More Books

Students also viewed these Databases questions

Question

Define self-esteem and discuss its impact on your life.

Answered: 1 week ago

Question

Explain the concept of shear force and bending moment in beams.

Answered: 1 week ago