Java Test 3 Part A

32 Questions | Total Attempts: 55

SettingsSettingsSettings
Java Quizzes & Trivia

This section consists of 20 questions.


Questions and Answers
  • 1. 
    When using a switch statement in Java, a no-match condition results in an error.
    • A. 

      True

    • B. 

      False

  • 2. 
    0.025 >= 0.333The result of relational operations will be
    • A. 

      True

    • B. 

      False

  • 3. 
    (-6<0) && (12 >= 10)The result of this operation will be
    • A. 

      True

    • B. 

      False

  • 4. 
    (5!=5)&&(3<6)The result of this operation will be
    • A. 

      True

    • B. 

      False

  • 5. 
    Int x = -7;int y = 3;!(3*x < 4*y) && (5*x >=y)The result of this expression will be
    • A. 

      True

    • B. 

      False

  • 6. 
    The default case is required in the switch selection statement.
    • A. 

      True

    • B. 

      False

  • 7. 
    The expression ((x > y) && (a < b)) is true if either x > y is true or a < b is true.
    • A. 

      True

    • B. 

      False

  • 8. 
    An expression containing the || operator is true if either or both of its operands are true.
    • A. 

      True

    • B. 

      False

  • 9. 
    The loop body of the do/while loop will be executed at least ___ time(s).
    • A. 

      0

    • B. 

      1

    • C. 

      2

    • D. 

      None of above

  • 10. 
    The loop body of the while loop will be executed at least ____ time(s)
    • A. 

      0

    • B. 

      1

    • C. 

      2

    • D. 

      None of above

  • 11. 
    A do/while loop is a post-test loop.
    • A. 

      True

    • B. 

      False

  • 12. 
    How many times will the following loop execute?int x = 1;do {   System.out.println("This is a do/while loop");   ++x;}while(x >= 0);
    • A. 

      0

    • B. 

      1

    • C. 

      2

    • D. 

      Infinite

  • 13. 
    How many times is the following loop executed?for (int x=0; x <= 10; ++x)     System.out.println("This is a for loop.");
    • A. 

      0

    • B. 

      1

    • C. 

      11

    • D. 

      Infinite

  • 14. 
    Consider the following segment of code:if (x>=0)   if (x<10)   {       y = x * x;       if (x<=5)           x = x - 2;    } //END if x < 10    else       y = 10 + x;else    y = x * x * x;io.writeInfo("x = " + x + "\ny = " +y);What will be displayed by the program if x = 0?
    • A. 

      X = 0 y = 0

    • B. 

      X = 0 y = 10

    • C. 

      X = -2 y = 0

    • D. 

      X = -2 y = 10

  • 15. 
    Consider the following segment of code:if (x>=0)   if (x<10)   {       y = x * x;       if (x<=5)           x = x - 2;    } //END if x < 10    else       y = 10 + x;else    y = x * x * x;io.writeInfo("x = " + x + "\ny = " +y);What will be displayed by the program if x = 4?
    • A. 

      X = 4 y = 64

    • B. 

      X = 2 y = 16

    • C. 

      X = 4 y = 16

    • D. 

      X = 4 y = 14

  • 16. 
    Consider the following segment of code:if (x>=0)   if (x<10)   {       y = x * x;       if (x<=5)           x = x - 2;    } //END if x < 10    else       y = 10 + x;else    y = x * x * x;io.writeInfo("x = " + x + "\ny = " +y);What will be displayed by the program if x = 6?
    • A. 

      X = 6 y =36

    • B. 

      X = 4 y = 36

    • C. 

      X = 6 y = 16

    • D. 

      X =4 y = 64

  • 17. 
    Consider the following segment of code:if (x>=0)   if (x<10)   {       y = x * x;       if (x<=5)           x = x - 2;    } //END if x < 10    else       y = 10 + x;else    y = x * x * x;io.writeInfo("x = " + x + "\ny = " +y);What will be displayed by the program if x = -5?
    • A. 

      X = -5 y = 25

    • B. 

      X = -7 y = 25

    • C. 

      X = -5 y = 5

    • D. 

      X = -5 y = -125

  • 18. 
    Consider the following segment of code:if (x>=0)   if (x<10)   {       y = x * x;       if (x<=5)           x = x - 2;    } //END if x < 10    else       y = 10 + x;else    y = x * x * x;io.writeInfo("x = " + x + "\ny = " +y);What will be displayed by the program if x = 10?
    • A. 

      X = 10 y = 100

    • B. 

      X = 8 y = 100

    • C. 

      X = 10 y = 20

    • D. 

      X = 10 y = 1000

  • 19. 
    Consider the following switch statement:int x = 3;switch (power) {   case 0 : io.writeInfo("1");                break;   case 1 : io.writeInfo(x);                break;   case 2 : io.writeInfo(x * x);                break;   case 3 : io.writeInfo(x * x * x);                break;   case 4 : io.writeInfo(x * x * x * x);                break;   default : io.writeInfo("No match exists for this power");}//END switchWhat will be displayed by the code if power = 0?
    • A. 

      1

    • B. 

      3

    • C. 

      9

    • D. 

      27

    • E. 

      81

  • 20. 
    Consider the following switch statement:int x = 3;switch (power) {   case 0 : io.writeInfo("1");                break;   case 1 : io.writeInfo(x);                break;   case 2 : io.writeInfo(x * x);                break;   case 3 : io.writeInfo(x * x * x);                break;   case 4 : io.writeInfo(x * x * x * x);                break;   default : io.writeInfo("No match exists for this power");}//END switchWhat will be displayed by the code if power = 1?
    • A. 

      1

    • B. 

      3

    • C. 

      9

    • D. 

      27

    • E. 

      81

  • 21. 
    Consider the following switch statement:int x = 3;switch (power) {   case 0 : io.writeInfo("1");                break;   case 1 : io.writeInfo(x);                break;   case 2 : io.writeInfo(x * x);                break;   case 3 : io.writeInfo(x * x * x);                break;   case 4 : io.writeInfo(x * x * x * x);                break;   default : io.writeInfo("No match exists for this power");}//END switchWhat will be displayed by the code if power = 2?
    • A. 

      1

    • B. 

      3

    • C. 

      9

    • D. 

      27

    • E. 

      81

  • 22. 
    Consider following program segment.int a = 1;while (17 % a != 5){    System.out.println(a + "  " + 17 % a);    ++a;}// END whileHow many times will the loop be executed?
    • A. 

      0 time

    • B. 

      1 time

    • C. 

      3 times

    • D. 

      5 times

  • 23. 
    Consider the following program segmentint b = 2;do {    System.out.println(b + "  " + b/5);    b = b + 2;}while ( b != 20);How many times will the loop be executed?
    • A. 

      1

    • B. 

      5

    • C. 

      9

    • D. 

      10

  • 24. 
    Determine the output generated by the following program segment.int number = 1;int product = 1;do {   ++ number;   product = product * number;} while ( number < 5);io.writeInfo("The product is: " + product);
    • A. 

      The product is 1

    • B. 

      The product is 24

    • C. 

      The product is 120

    • D. 

      The product is 2

  • 25. 
    Which of the following is NOT an iteration control structure in Java?
    • A. 

      For

    • B. 

      Switch

    • C. 

      While

    • D. 

      Do/while

Back to Top Back to top