Examlex

Solved

Consider the Following Method

question 104

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?


Definitions:

Dressmaking Company

A business that specializes in creating clothing according to specific designs and measurements, often providing custom tailoring services.

Manufacturing Business

An enterprise engaged in the industrial production of goods from raw materials through the use of labor, machinery, and equipment.

Men's Clothing Store

A retail establishment specializing in clothing for men, offering a variety of apparel and accessories.

Retail Business

A commercial strategy where products are sold directly to end-users, usually in small amounts.

Related Questions