Limited access

Upgrade to access all content for this subject

Which of the following code fragments will result in a StringIndexOutOfBoundsException?

A
int sum = 0;
String sport = "football";
for (int i=0; i<sport.length()-1; i++)
{
    if (sport.substring(i,i+1).equals(sport.substring(i+1,i+2)))
        sum+=i;
}
System.out.println(sum);
B
String sport = "basketball";
System.out.println(sport.substring(sport.length()));
C
int count = 0;
String sport = "baseball";
for (int i=0; i<sport.length(); i++)
{
    if (sport.substring(i,i+2).equals("ba"))
       count+=1;
}
System.out.println(count);
D
String sport = "hockey";
System.out.println(sport.substring(0,sport.length()));
E
String sport = "tennis";
System.out.println("9 + 1 = " + sport.substring(0,sport.length()-3));
Select an assignment template