Java Test 3 Part A

32 Questions | Attempts: 55
Share

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

    Correct Answer
    B. False
  • 2. 

    0.025 >= 0.333The result of relational operations will be

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
  • 3. 

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

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
  • 4. 

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

    • A.

      True

    • B.

      False

    Correct Answer
    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

    Correct Answer
    B. False
  • 6. 

    The default case is required in the switch selection statement.

    • A.

      True

    • B.

      False

    Correct Answer
    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

    Correct Answer
    B. False
  • 8. 

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

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
  • 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

    Correct Answer
    B. 1
  • 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

    Correct Answer
    A. 0
  • 11. 

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

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
  • 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

    Correct Answer
    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

    Correct Answer
    C. 11
  • 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

    Correct Answer
    C. X = -2 y = 0
  • 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

    Correct Answer
    B. X = 2 y = 16
  • 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

    Correct Answer
    A. X = 6 y =36
  • 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

    Correct Answer
    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

    Correct Answer
    C. X = 10 y = 20
  • 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

    Correct Answer
    A. 1
  • 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

    Correct Answer
    B. 3
  • 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

    Correct Answer
    C. 9
  • 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

    Correct Answer
    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

    Correct Answer
    C. 9
  • 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

    Correct Answer
    B. The product is 24
  • 25. 

    Which of the following is NOT an iteration control structure in Java?

    • A.

      For

    • B.

      Switch

    • C.

      While

    • D.

      Do/while

    Correct Answer
    B. Switch
  • 26. 

    The continue statement is used to immediately terminate a loop.

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
  • 27. 

    The continue statement is used to skip over a single loop iteration.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
  • 28. 

    The loop counter in a for loop is altered after the loop body is executed in a given iteration.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
  • 29. 

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

    • A.

      0

    • B.

      1

    • C.

      2

    • D.

      Infinite

    Correct Answer
    A. 0
  • 30. 

    Suppose that you have two nested loops. The inner loop executes five times and the outer loop executes ten times. How many total iterations are there within the nested loop structure?

    • A.

      15 total iterations

    • B.

      20 total iterations

    • C.

      50 total iterations

    • D.

      100 total iterations

    Correct Answer
    C. 50 total iterations
  • 31. 

    An else must always have a corresponding if.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
  • 32. 

    A statement that can be inserted at the end of a switch statement to protect against invalid entries is the ___________ statement

    • A.

      Break

    • B.

      Default

    • C.

      Case

    • D.

      Initial

    Correct Answer
    B. Default

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 18, 2022
    Quiz Edited by
    ProProfs Editorial Team
  • Nov 22, 2009
    Quiz Created by
    Yupeilin
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.