Explore BrainMass

Explore BrainMass

    Java - What does the following program do? MysteryClass

    Not what you're looking for? Search our solutions OR ask your own Custom question.

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    // Exercise 15.12 Solution: MysteryClass.java

    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

    // Exercise 15.12 Solution

    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

    © BrainMass Inc. brainmass.com December 24, 2021, 6:38 pm ad1c9bdddf
    https://brainmass.com/computer-science/java/java-what-does-the-following-program-do-mysteryclass-127716
    $2.49

    ADVERTISEMENT