Determine the working of mysteryclass program


Discuss the below:

Q: What does the following program do?

MysteryClass

public class MysteryClass
{
public int mystery( int array2[], int size )
{
if ( size == 1 )
return array2[ 0 ];
else
return array2[ size - 1 ] + mystery( array2, size - 1 );
} // end method mystery
} // end class MysteryClass

public class MysteryTest
{
public static void main( String arg[] )
{
MysteryClass mysteryObject = new MysteryClass();
int array[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int result = mysteryObject.mystery( array, array.length );
System.out.printf( "Result is: %dn", result );
} // end method main
} // end class MysteryTest

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Determine the working of mysteryclass program
Reference No:- TGS01935377

Now Priced at $25 (50% Discount)

Recommended (95%)

Rated (4.7/5)