java - Why does this code not return just "S" but instead the whole String MINUS the "S" -
I am new to APCS and I am practicing for my test. After analyzing this code with step-by-step analysis, I believe the answer is not listed below, but instead it is "S". However, my teacher says that the answer is "D"
< P> Can you explain this question to me?Looking at the following method:
public static string WhatsUp (string str1, string strings 2) {int index = straw.andexoff (straw2); If (index! = -1) str1 = str1.substring (0, index) + str1.substring (index + str2.length ()); Return str1; }
What is this line of code output?
System.out.print (WhatsUp ("SpongeBobSquarePants", "S"));
P>
(E) Patrick
index index = str1.indexOf (Str2);
Index is set to 0
str1.substring (0, index)
This returns nothing (Index is zero, ending point is exclusive (not included)
public string object (int startIndex, int and index)
a new String gives a substring of this string. The start of the object starts with the alphabet specified on the index and index-1. Thus, By and Index -andex.
+ str1.substring (index + str2.length ());
This position is 1 Returns everything
return str1;
answer is
Comments
Post a Comment