Question: The second and final time inside the loop while, a.substring(x+b.length()) is out of bounds because x+b.length() is 11 while a.length() = 10. Please explain clearly

 The second and final time inside the loop while, a.substring(x+b.length()) isThe second and final time inside the loop while, a.substring(x+b.length()) is out of bounds because x+b.length() is 11 while a.length() = 10. Please explain clearly why it is not out of bounds. Correct answer is B.
First time inside loop
a = "si the song"
x= 9
Second time
a = "si the so" + a.substring(9+2) which is out of bounds

28. Consider the following method. public static String abMethod(String a, String b) int x = a.indexOf(b); while (x >= 0) { a = a.substring(o, x) + a.substring(x + b. length(); x = a.indexOf(b); } return a; 1 What, if anything, is returned by the method call abMethod("sing the song", "ng") ? (A) "si" (B) "si the so" (C) "si the song " (D) "sig the sog" (E) Nothing is returned because a StringIndexOutOfBoundsException is thrown

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!