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
View Answer
Unlock this answer now
Get Access to more Verified Answers free of charge
Q92: Consider the following code; instantiate the buttons
Q93: Consider the following code:
import javafx.scene.control.*;
import javafx.scene.layout.*;
public class
Q94: Consider the following code and place bottomBox
Q95: Consider the following code:
import javafx.scene.control.*;
import javafx.scene.layout.*;
public class
Q96: Consider the following method:
// Assume that n
Q98: Code a recursive method that counts how
Q99: Code a recursive method that takes a
Q100: Code a recursive method that takes a
Q101: Consider the following state of a
Q102: Consider the following state of a
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents