Essay
Consider the following method:
public static int foo( String s1, String s2, int i )
{
if ( s2.length( ) > s1.length( ) )
return -1;
else if ( s1.substring( 0, s2.length( ) ).equals( s2 ) )
return i;
else
return foo( s1.substring( 1, s1.length( ) ), s2, i + 1 );
}
What is the output of the following code?
System.out.println( foo( "AB", "XYZ", 0 ) );
What is the output of the following code?
System.out.println( foo( "ABC", "A", 0 ) );
What is the output of the following code?
System.out.println( foo( "ABCDEFG", "DE", 0 ) );
What does foo( s1, s2, 0 ) return as a function of s1 and s2?
Correct Answer:

Verified
// System.out.println( foo( "AB", "XYZ",...View Answer
Unlock this answer now
Get Access to more Verified Answers free of charge
Correct Answer:
Verified
View Answer
Unlock this answer now
Get Access to more Verified Answers free of charge
Q99: An array, numbers, has been declared and
Q100: A method is coded as follows:<br>public static
Q101: Code a method that returns an int
Q102: The variable numbers is a two-dimensional array
Q103: We have coded the following sequence:<br>try<br>{<br>Scanner scan
Q105: Give the values that are assigned to
Q106: We have already coded the class User.
Q107: Write Java statements to instantiate a random
Q108: The class Ticket has been coded as
Q109: If you want to use the Random