For Questions 33 to 37, consider the following statement:
String [ ][ ] geo = { { “MD”, “NY”, “NJ”, “MA”, “ME”, “CA”, “MI”, “OR” },{ “Detroit”, “Newark”, “Boston”, “Seattle” } };
// your code goes here
System.out.println( geo[1][2] );
For Questions 33 to 37, consider the following statement:
String [ ][ ] geo = { { “MD”, “NY”, “NJ”, “MA”, “ME”, “CA”, “MI”, “OR” },{ “Detroit”, “Newark”, “Boston”, “Seattle” } };
// your code goes here
System.out.println( geo[0][5] );
For Questions 33 to 37, consider the following statement:
String [ ][ ] geo = { { “MD”, “NY”, “NJ”, “MA”, “ME”, “CA”, “MI”, “OR” },{ “Detroit”, “Newark”, “Boston”, “Seattle” } };
for ( int j = 0; j < geo[0].length; j++ )
{
// your code goes here
}for ( int j = 0; j < geo[0].length; j++ )
{
if ( geo[0][j].charAt( 0 ) == 'M' )
System.out.println( geo[0][j] );
}For Questions 33 to 37, consider the following statement:
String [ ][ ] geo = { { “MD”, “NY”, “NJ”, “MA”, “ME”, “CA”, “MI”, “OR” },{ “Detroit”, “Newark”, “Boston”, “Seattle” } };
for ( int j = 0; j < geo[1].length; j++ )
{
// your code goes here
}for ( int j = 0; j < geo[1].length; j++ )
{
System.out.println( geo[1][j] );
}
For Questions 33 to 37, consider the following statement:
String [ ][ ] geo = { { “MD”, “NY”, “NJ”, “MA”, “ME”, “CA”, “MI”, “OR” },{ “Detroit”, “Newark”, “Boston”, “Seattle” } };
for ( int i = 0; i < geo.length; i++ )
{
// your code goes here
}for ( int i = 0; i < geo.length; i++ )
{
for ( int j = 0; j < geo[i].length; j++ )
System.out.println( geo[i][j] );
}For Questions 38 to 41, consider the following statement:
int [ ][ ] a = { { 9, 6, 8, 10, 5 },
{ 7, 6, 8, 9, 6 },
{ 4, 8, 10, 6, 6 } };
int sum = 0;
for ( int i = 0; i < a.length; i++ )
{
// your code goes here
}
System.out.println( "sum is " + sum );int sum = 0;
for ( int i = 0; i < a.length; i++ )
{
for ( int j = 0; j < a[i].length; j++ )
sum += a[i][j];
}
System.out.println( "The sum is " + sum );For Questions 38 to 41, consider the following statement:
int [ ][ ] a = { { 9, 6, 8, 10, 5 },
{ 7, 6, 8, 9, 6 },
{ 4, 8, 10, 6, 6 } };
int count = 0;
for ( int i = 0; i < a.length; i++ )
{
// your code goes here
}
System.out.println( "# of 8s in a: " + count );int count = 0;
for ( int i = 0; i < a.length; i++ )
{
for ( int j = 0; j < a[i].length; j++ )
{
if ( a[i][j] == 8 )
count++;
}
}
System.out.println( "# of 8s in a: " + count );For Questions 38 to 41, consider the following statement:
int [ ][ ] a = { { 9, 6, 8, 10, 5 },
{ 7, 6, 8, 9, 6 },
{ 4, 8, 10, 6, 6 } };
int count = 0;
// your code for the for loop header goes here
{
if ( a[1][j] == 6 )
count++;
}
System.out.println( “# of 6s in the 2nd row: “ + count );
int count = 0;
for ( int j = 0; j < a[1].length; j++ )
{
if ( a[1][j] == 6 )
count++;
}
System.out.println( "# of 6s in the 2nd row: " + count );For Questions 38 to 41, consider the following statement:
int [ ][ ] a = { { 9, 6, 8, 10, 5 },
{ 7, 6, 8, 9, 6 },
{ 4, 8, 10, 6, 6 } };
int sum = 0;
for ( int i = 0; i < a.length; i++ )
{
// your code goes here}
System.out.println( “sum is “ + sum );
int sum = 0;
for ( int i = 0; i < a.length; i++ )
{
if ( a[i].length >= 2 )
sum += a[i][1];
}
System.out.println( "sum is " + sum );public static boolean foo( String [ ][ ] a )
{
// your code goes here
}public static boolean foo( String [][] a )
{
for( int i = 0; i < a.length; i++ )
{
for ( int j = 0; j < a[i].length; j++ )
{
if ( a[i][j].equals( "Java" ) )
return true;
}
}
return false;
}public static int foo( int [ ][ ] a )
{
// your code goes here
}public static int foo( int [][] a )
{
int product = 1;
for ( int i = 0; i < a.length; i++ )
{
for ( int j = 0; j < a[i].length; j++ )
{
product *= a[i][j];
}
}
return product;
}public static boolean foo( char [ ][ ] a )
{
// your code goes here
}public static boolean foo( char [][] a )
{
for ( int i = 0; i < a.length; i++ )
{
if ( a[i].length == 5 )
return true;
}
return false;
}public static boolean [ ] foo( int [ ][ ] a )
{
// your code goes here
// every row has the same number of columns
}public static boolean [] foo( int [][] a )
{
boolean [] temp = new boolean[a.length];
for ( int i = 0; i < a.length; i++ )
{
for ( int j = 0; j < a[i].length; j++ )
{
if ( a[i][j] == 0 )
temp[i] = true;
}
}
return temp;
}For Questions 46 to 49, consider the following statements:
ArrayList languages = new ArrayList( );
languages. add( “SQL” );
languages. add( “Java” );
languages. add( “HTML” );
languages. add( “PHP” );
languages. add( “Perl” );
// your code goes here
System.out.println( languages.size( ) );
For Questions 46 to 49, consider the following statements:
ArrayList languages = new ArrayList( );
languages. add( “SQL” );
languages. add( “Java” );
languages. add( “HTML” );
languages. add( “PHP” );
languages. add( “Perl” );
// your code goes here
String webLanguage = languages.get( 2 );
For Questions 46 to 49, consider the following statements:
ArrayList languages = new ArrayList( );
languages. add( “SQL” );
languages. add( “Java” );
languages. add( “HTML” );
languages. add( “PHP” );
languages. add( “Perl” );
// your code goes here
languages.set( 2, “C++” );
For Questions 46 to 49, consider the following statements:
ArrayList languages = new ArrayList( );
languages. add( “SQL” );
languages. add( “Java” );
languages. add( “HTML” );
languages. add( “PHP” );
languages. add( “Perl” );
for ( String s : languages )
{
// your code goes here
}for ( String s : languages )
{
if ( s.charAt( 0 ) == 'P' )
System.out.println( s );
}