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:

Income Statement

A financial statement that shows a company's revenues and expenses over a specific period, culminating in net income or loss.

Net Income

The concluding profit margin of a company after deducting all operational expenditures and taxes from its income.

Revenues

Income that a company receives from its normal business activities, usually from the sale of goods and services to customers.

Beginning Inventory

The amount of goods presented for buying at the initial stage of an accounting term.

Related Questions