Question: The original code: Slightly modified code: I am getting an error: java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1 at Debug.main(Debug.java:11) I'm a bit

The original code:
Slightly modified code:
I am getting an error: "java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1 at Debug.main(Debug.java:11)" I'm a bit stuck with how to debug this.
In the starter code, a file named Debug . java is given. The class Debug has a main method. This method has to take a string array as its parameter from the command line, consider the initial argument of the array as a keyword, and print the number of occurrences that the keyword appears in the rest of the array. The code has several runtime errors. Fix the errors so that the code satisfies the following: 1. If the input array is empty, then the output should print No keyword is given 2. If the input array is not empty, the initial argument should be a keyword with the prefix -- (two dashes). If the argument does not satisfy this format, then the output should print Write a keyword with the prefix -- 3. If the input array is not empty and the keyword is given in the correct format, then calculate the count of occurrences of the keyword after the initial argument. If the array has only one string, then the count is 0 . The output should print The answer is [count] Examples: \$ javac Debug.java $ java Debug No keyword is given \$ java Debug melon Write a keyword with the prefix -- \$ java Debug --melon The answer is 0 \$ java Debug --melon apple orange melon watermelon melon banana The answer is 2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
