Limited access

Upgrade to access all content for this subject

Consider the following code.

// Return the count of the number of times c is found in phrase
// Precondition: c is a single character
public static int countChar(String phrase, String c)
     int count=0;
     for (int i=0; i<phrase.length(); i++);
        if (phrase.substring(i, i+1).equals(c))
     return count;

Which of the following BEST describe why this code will not compile successfully?


The method will throw an ArrayIndexOutOfBoundsException.


There is a syntax error: i cannot be resolved as a variable in the if statement.


The returned count is always too high.


The substring command is causing an OutOfBoundsException.


Nothing is wrong with the code. It should function as expected.

Select an assignment template