1.7 Review Exercises

  1. What will this program print?

    print("Here we are ");
    println("(finally),\n");
    print("at the end\nof\n");
    println("\nChapter 1");
  2. Write a single Processing statement that will print the following, exactly as shown.

    The handsome stranger said,
    "My name is Kim, Paul Kim."
  3. State the type of each legal constant. If the constant is illegal, explain why.

  4. What is the smallest type of integer that could be used to represent each of the following values?
    (a) 400          (c) -100
    (b) 50 000       (d) 3 000 000 000
    
  5. Rewrite in standard decimal form
    (a) 8.77e-4   (b) 299.04eO
    (c) -0.0443E6 (d) -23e-4
    			
  6. Identify, with reasons, any identifiers that should not be used for Processing variables.
    (a) 1stTime            (b) Perimeter
    (c) valueln$           (d) beginning
    (e) average height     (f) case
    
  7. Which of the following conversions always requires a cast?
    (a) long to double      (b) byte to char
    (c) float to double     (d) byte to long
    (e) short to char       (f) double to long
  8. What would be printed by each fragment?
    (a) 
    
    float x = 0.093e-1, y = -3e-3;
    println("x: " + x + "y: " + y);
    (b)
    int i = 5, j = -77;
    println("first is "+i+"\nsecond is "+j);
  9. The following program contains five known syntax errors. Rewrite the program with those errors corrected.
    void setup
    /* another mess *\
    {
       int i = 7; j = 3;
       print("Smaller is " + i);
       printLn(" Larger is " + j)
    }
    
  10. Write and run an interactive program that asks the user to provide a string, a character, an integer, and a floating point value. After reading the values, the program should print each one on a separate line with a suitable message for each line of output.
  11. Create a sketch window that is 500 x 500 in size. Draw a red square that is 100 x 100 at the bottom right corner. Draw a green circle that has a radius of 50 and just touches the top left corner of the screen. Draw a blue triangle with a black outline that goes through the following points: (150,150), (150, 250), (300, 200).