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 ] );
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started