Question: 1. What is the output of the following code segment? int array[] = { 8, 6, 9, 7, 6, 4, 4, 5, 8, 10 };

1. What is the output of the following code segment?

int array[] = { 8, 6, 9, 7, 6, 4, 4, 5, 8, 10 };

System.out.println( "Index Value" );

for ( int i = 0; i < array.length; i++ )

System.out.printf( "%d %d ", i, array[ i ] );

Answer:

\

2. What is the output of the following code segment?

char sentence[] = {'H', 'o', 'w', ' ', 'a', 'r', 'e', ' ', 'y', 'o', 'u' };

String output = "The sentence is: ";

for ( int i = 0; i < sentence.length; i++ )

System.out.printf( "%c ", sentence[ i ] );

System.out.println();

Answer:

3. What is the output of the following code segment?

int array[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

for ( int i = 0; i < array.length; i++ )

{

for ( int j = 0; j < array [ i ]; j++ )

System.out.print( "*" );

System.out.println();

Answer:

4. What is the output of the following code segment?

int array[] = { 3, 2, 5 };

for ( int i = 0; i < 3; i++ )

array[ i ] *= 2;

for ( int j : array )

System.out.print( "%d ", j );

System.out.println();

Answer:

Given the following declaration of a method

public int method1( int... values )

{

int mystery = 1;

for ( int i : values )

mystery *= i;

return mystery;

}

5. What is the output of the following code segment?

System.out.println( method1( 1, 2, 3, 4, 5 ) );

Answer:

Given the following declaration of a method

public int method1( int values[][] )

{

int mystery = 1;

for ( int i[] : values )

for ( int j : i )

mystery *= j;

return mystery;

}

6. What is the output of the following code segment?

int array[][] = { { 3, 2, 5 }, { 2, 2, 4, 5, 6 }, { 1, 1 } };

System.out.println( mystery( array ) );

Answer:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!