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

Test

Chapter 2 Operators and Statements

davidv 20 preguntas

Hacer el test

Preguntas del test (20)

  1. 1Which of the following Java operators can be used with boolean variables? (Choose all that
    apply)
    1. AA. ==
    2. BB. +
    3. CC. --
    4. DD. !
    5. EE. %
    6. FF. <=
  2. 2What data type (or types) will allow the following code snippet to compile? (Choose all that
    apply)
    byte x = 5;
    byte y = 10;
    _____ z = x + y;
    1. AA. int
    2. BB. long
    3. CC. boolean
    4. DD. double
    5. EE. short
    6. FF. byte
  3. 3What is the output of the following application?
    1: public class CompareValues {
    2: public static void main(String[] args) {
    3: int x = 0;
    4: while(x++ < 10) {}
    5: String message = x > 10 ? "Greater than" : false;
    6: System.out.println(message+","+x);
    7: }
    8: }
    1. AA. Greater than,10
    2. BB. false,10
    3. CC. Greater than,11
    4. DD. false,11
    5. EE. The code will not compile because of line 4.
    6. FF. The code will not compile because of line 5.
  4. 4What change would allow the following code snippet to compile? (Choose all that apply)
    3: long x = 10;
    4: int y = 2 * x;
    1. AA. No change; it compiles as is.
    2. BB. Cast x on line 4 to int.
    3. CC. Change the data type of x on line 3 to short.
    4. DD. Cast 2 * x on line 4 to int.
    5. EE. Change the data type of y on line 4 to short.
    6. FF. Change the data type of y on line 4 to long.
  5. 5What is the output of the following code snippet?
    3: java.util.List<Integer> list = new java.util.ArrayList<Integer>();
    4: list.add(10);
    5: list.add(14);
    6: for(int x : list) {
    7: System.out.print(x + ", ");
    8: break;
    9: }
    1. AA. 10, 14,
    2. BB. 10, 14
    3. CC. 10,
    4. DD. The code will not compile because of line 7.
    5. EE. The code will not compile because of line 8.
    6. FF. The code contains an infinite loop and does not terminate.
  6. 6What is the output of the following code snippet?
    3: int x = 4;
    4: long y = x * 4 - x++;
    5: if(y<10) System.out.println("Too Low");
    6: else System.out.println("Just right");
    7: else System.out.println("Too High");
    1. AA. Too Low
    2. BB. Just Right
    3. CC. Too High
    4. DD. Compiles but throws a NullPointerException.
    5. EE. The code will not compile because of line 6.
    6. FF. The code will not compile because of line 7.
  7. 7What is the output of the following code?
    1: public class TernaryTester {
    2: public static void main(String[] args) {
    3: int x = 5;
    4: System.out.println(x > 2 ? x < 4 ? 10 : 8 : 7);
    5: }}
    1. AA. 5
    2. BB. 4
    3. CC. 10
    4. DD. 8
    5. EE. 7
    6. FF. The code will not compile because of line 4.
  8. 8What is the output of the following code snippet?
    3: boolean x = true, z = true;
    4: int y = 20;
    5: x = (y != 10) ^ (z=false);
    6: System.out.println(x+", "+y+", "+z);
    1. AA. true, 10, true
    2. BB. true, 20, false
    3. CC. false, 20, true
    4. DD. false, 20, false
    5. EE. false, 20, true
    6. FF. The code will not compile because of line 5.
  9. 9How many times will the following code print "Hello World"?
    3: for(int i=0; i<10 ; ) {
    4: i = i++;
    5: System.out.println("Hello World");
    6: }
    1. AA. 9
    2. BB. 10
    3. CC. 11
    4. DD. The code will not compile because of line 3.
    5. EE. The code will not compile because of line 5.
    6. FF. The code contains an infinite loop and does not terminate.
  10. 10What is the output of the following code?
    3: byte a = 40, b = 50;
    4: byte sum = (byte) a + b;
    5: System.out.println(sum);
    1. AA. 40
    2. BB. 50
    3. CC. 90
    4. DD. The code will not compile because of line 4.
    5. EE. An undefined value.

Información

Descripción
OCA java 8 JAVA 8 Test sobre Chapter 2 Operators and Statements, creado por davidv el 23/04/2016.
Autor
davidv
Idioma
Español
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?