Quiz Questions
For Chapter 3


THIS PAGE CONTAINS A SAMPLE quiz on material from Chapter 3 of this on-line Java textbook. You should be able to answer these questions after studying that chapter. Sample answers to all the quiz questions can be found here.


Question 1: Explain briefly what is meant by "pseudocode" and how is it useful in the development of algorithms.

Question 2: What is a block statement? How are block statements used in Java programs.

Question 3: What is the main difference between a while loop and a do..while loop?

Question 4: What does it mean to prime a loop?

Question 5: Explain what is meant by an animation and how a computer displays an animation.

Question 6: Write a for loop that will print out all the multiples of 3 from 3 to 36, that is: 3 6 9 12 15 18 21 24 27 30 33 36.

Question 7: Fill in the following main() routine so that it will ask the user to enter an integer, read the user's response, and tell the user whether the number entered is even or odd. (You can use TextIO.getInt() to read the integer. Recall that an integer n is even if n % 2 == 0.)

                public static void main(String[] args) {
                
                        // Fill in the body of this subroutine!
                
                }
                

Question 8: Show the exact output that would be produced by the following main() routine:

         public static void main(String[] args) {
             int N;
             N = 1;
             while (N <= 32) {
                N = 2 * N;
                System.out.println(N);   
             }
         }
         

Question 9: Show the exact output produced by the following main() routine:

              public static void main(String[] args) {
                 int x,y;
                 x = 5;
                 y = 1;
                 while (x > 0) {
                    x = x - 1;
                    y = y * x;
                    System.out.println(y);
                 }
              }
              

Question 10: What output is produced by the following program segment? Why? (Recall that name.charAt(i) is the i-th character in the string, name.)

         String name;
         int i;
         boolean startWord;

         name = "Richard M. Nixon";
         startWord = true;
         for (i = 0; i < name.length(); i++) {
            if (startWord)
               System.out.println(name.charAt(i));
            if (name.charAt(i) == ' ')
               startWord = true;
            else
               startWord = false;
         }

[ Answers | Chapter Index | Main Index ]