CS110 Practice Quiz 8

More looping structures




  Choose the best alternative:
  1. The do/while loop breaks when the boolean test condition is FALSE.
  2. The do/while loop is a post-test loop.
  3. The while loop is known as a post-test loop.
  4. The while loop will always execute at least once. (A one-trip loop.)
    .
  5. The do/while loop will always execute at least once. (A one-trip loop.)
  6. What output is produced by the segment of code shown below:
    int i = 1;
    while (i <= 5)
    {   System.out.print('A');
        i++;
    }
  7. The segment of code below will result in .
    int i = 0;
    while (i <= 2)
    {   System.out.print('A'); }
  8. What output is produced by the segment of code shown below:
    static final int MAX = 4; //DECLARED GLOBAL

    int f = 3;
    while (f > MAX)
       f = f - 2;
    System.out.print(f) ;
  9. What output is produced by the segment of code shown below:
    static final int MAX = 4; //DECLARED GLOBAL

    int f = 3;
    do
       f -= 2;
    while (f > MAX);
    System.out.print(f);
  10. The output produced by the segment of code shown below is .
    int x = 3;
    do
        System.out.print(x);
    while (x >=3);
  11. What output is produced by the segment of code shown below:
    char c = 'a';
    while (c <= 'f')
    {     c += 2;
        System.out.print(c);
    }
  12. What output is produced by the segment of code shown below:
    int i = 1;
    do
    {   i++;
       System.out.print(i);
        i++;
    }
    while (i <= 10);


Answers

  1. false.
  2. true.
  3. false. The only post-test loop is the do..while loop.
  4. false. The while loop is a zero-trip loop.
  5. true. The do..while loop is a post-test loop and will execute at least once.
  6. AAAAA
  7. An infinite loop.
  8. 3. NOTE: The loop boolean condition was false at the start.
  9. 1
  10. an infinite loop.
  11. ceg
  12. 246810