Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 ] );

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();

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();

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();

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 ) );

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 ) );

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Flash XML Applications Use AS2 And AS3 To Create Photo Galleries Menus And Databases

Authors: Joachim Schnier

1st Edition

0240809173, 978-0240809175

More Books

Students also viewed these Databases questions

Question

Find the Z parameters in terms of the ABCD parameters

Answered: 1 week ago

Question

10-2 What are the principal e-commerce business and revenue models?

Answered: 1 week ago

Question

Select suitable tools to analyze service problems.

Answered: 1 week ago