¡GoConqr estrena diseño! Cuéntanos qué te parece.

Test

02-Objective-Wise-Creating-Using-Array

Wong Fei Hung 20 preguntas

Hacer el test

Preguntas del test (20)

  1. 1public class TestClass {
    int[ ] [ ] matrix = new int[ 2] [ 3] ;
    int a[ ] = { 1, 2, 3} ;
    int b[ ] = { 4, 5, 6} ;
    public int compute( int x, int y) {
    //1 : Insert Line of Code here
    }p
    ublic void loadMatrix( ) {
    for( int x=0; x<matrix. length; x++) {
    for( int y=0; y<matrix[ x] . length; y++) {
    //2: Insert Line of Code here
    }
    }
    }
    }What can be inserted at //1 and //2?
    1. Areturn a( x) *b( y) ;
      and
      matrix( x, y) = compute( x, y) ;
    2. Breturn a[ x] *b[ y] ;
      and
      return a[ x] *b[ y] ;
    3. Creturn a[ x] *b[ y] ;
      and
      matrix[ x] [ y] = compute( x, y) ;
    4. Dreturn a( x) *b( y) ;
      and
      matrix( x) ( y) = compute( x, y) ;
    5. Ereturn a[ x] *b[ y] ;
      and
      matrix[ [ x] [ y] ] = compute( x, y) ;
  2. 2Consider the following array definitions:
    int[ ] array1, array2[ ] ;
    int[ ] [ ] array3;
    int[ ] array4[ ] , array5[ ] ;
    Which ofthe following are valid statements?
    1. Aarray2 = array3;
    2. Barray2 = array4;
    3. Carray1 = array2;
    4. Darray4 = array1;
    5. Earray5 = array3
  3. 3What will be the result ofattempting to run the following program?
    public class StringArrayTest{
    public static void main( String args[ ] ) {
    String[ ] [ ] [ ] arr ={ { { " a" , " b" , " c" } , { " d" , " e" , null } } ,
    { { " x" } , null } , { { " y" } } , { { " z" , " p" } , { } }
    } ;
    System. out. println( arr[ 0] [ 1] [ 2] ) ;
    }
    }
    1. AIt will throw NullPointerBoundsException.
    2. BIt will throw ArrayIndexOutOfBoundsException.
    3. CIt will print null.
    4. DIt will run without any error but will print nothing.
    5. ENone ofthe above.
  4. 4Given the following declaration:
    int[ ] [ ] twoD = { { 1, 2, 3} , { 4, 5, 6, 7} , { 8, 9, 10 } } ;
    What will the following lines ofcode print?
    System. out. println( twoD[ 1] . length) ;
    System. out. println( twoD[ 2] . getClass( ) . isArray( ) ) ;
    System. out. println( twoD[ 1] [ 2] ) ;
    1. A4
      true
      6
    2. B3
      true
      3
    3. C3
      false
      3
    4. D4
      false
      6
  5. 5Consider the following program:
    public class TestClass{
    public static void main( String[ ] args) {
    String tom = args[ 0] ;
    String dick = args[ 1] ;
    String harry = args[ 2] ;
    }
    }Wha
    t will the value of'harry' ifthe program is run from the command line:
    java TestClass 111 222 333
    1. A111
    2. B222
    3. C333
    4. DIt will throw an ArrayIndexOutOfBoundsException
    5. ENone ofthe above.
  6. 6What will be the result oftrying to compile and execute ofthe following program?
    public class TestClass{
    public static void main( String args[ ] ) {
    int i = 0 ;
    int[ ] iA = { 10, 20} ;
    iA[ i] = i = 30 ;
    System. out. println( " " + iA[ 0 ] + " " + iA[ 1 ] + " " +i) ;
    }
    }
    1. AIt will throw ArrayIndexOutofBoundsException at Runtime.
    2. BCompile time Error.
    3. CIt will prints 10 20 30
    4. DIt will prints 30 20 30
    5. EIt will prints 0 20 30
  7. 7What will be the result ofattempting to compile and run the following class?
    public class TestClass{
    public static void main( String args[ ] ) {
    int i = 1;
    int[ ] iArr = { 1} ;
    incr( i) ;
    incr( iArr) ;
    System. out. println( " i = " + i + " iArr[ 0] = " + iArr [ 0 ] ) ;
    }p
    ublic static void incr( int n ) { n++ ; }
    public static void incr( int[ ] n ) { n [ 0 ] ++ ; }
    }
    1. AThe code will print i = 1 iArr[ 0] = 1;
    2. BThe code will print i = 1 iArr[ 0] = 2;
    3. CThe code will print i = 2 iArr[ 0] = 1;
    4. DThe code will print i = 2 iArr[ 0] = 2;
    5. EThe code will not compile.
  8. 8What will the following program print?
    class Test{
    public static void main( String[ ] args) {
    int i = 4;
    int ia[ ] [ ] [ ] = new int[ i] [ i = 3] [ i] ;
    System. out. println( ia. length + " , " + ia[ 0] . length+" , " + ia[ 0] [ 0] . length) ;
    }
    }
    1. AIt will not compile.
    2. B3, 4, 3
    3. C3, 3, 3
    4. D4, 3, 4
    5. E4, 3, 3
  9. 9What will the following program print?
    public class TestClass{
    public static void main( String[ ] args) {
    String str = " 111" ;
    boolean[ ] bA = new boolean[ 1] ;
    if( bA[ 0] ) str = " 222" ;
    System. out. println( str) ;
    }
    }
    1. A111
    2. B222
    3. CIt will not compile as bA[ 0] is uninitialized
    4. DNone ofthe above.
  10. 10What sequence ofdigits will the following program print?
    import j ava. util. * ;
    public class ListTest{
    public static void main( String args[ ] ) {
    List s1 = new ArrayList( ) ;
    s1. add( " a" ) ;
    s1. add( " b" ) ;
    s1. add( 1, " c" ) ;
    List s2 = new ArrayList( s1. subList( 1, 1) ) ;
    s1. addAll( s2) ;
    System. out. println( s1) ;
    }
    }
    1. AThe sequence a, b, c is printed.
    2. BThe sequence a, b, c, b is printed.
    3. CThe sequence a, c, b, c is printed.
    4. DThe sequence a, c, b is printed.
    5. ENone ofthe above.

Información

Descripción
OCA-SE-7 Objective-Wise-Ethuware-OCA-SE-7 Test sobre 02-Objective-Wise-Creating-Using-Array, creado por Wong Fei Hung el 30/07/2017.
Idioma
Português
Visitas
0
Valoración
Aún sin valoraciones
Valora este test
Valora este test

Escríbenos

¿Sobre qué es tu mensaje?

¿Qué te parece el nuevo diseño?

¿Te gusta?