Review Exercises - Class 1

  1. What is the difference between an int value and a double value?
  2. Declare a variable named average suitable for holding the average of three numbers. Hint: think about the type the variable should be.
  3. What is a compiler?
  4. What is a file with a suffix of .java?
  5. What is a file with a suffix of .class?
  6. What does the following statement do?
              StdOut.println("Val:" + 1 + 2 + (3 + 4)); 
          
    Explain what is going on.
  7. Assuming a, b, and c are appropriately declared variables convert the following formula to a Java expression: ax2+ bx + c
  8. What is output by the following code segment?
              double x;
              x = 9.0;
              StdOut.println(Math.sqrt(x));
              StdOut.println(Math.pow(x,2));  
             
  9. What does the Math.sqrt(x) function do?
  10. What does the Math.pow(x,y) function do?
  11. What does the function Math.rint(x) do? Experiment with this function in Java to figure out what it does.
  12. Without running this on the computer figure out what gets printed by the code segment below.
     
         int x = 7;
         int y = 9;
         int z = x + y / 4 * (x - 2);
         StdOut.println(z);
        
  13. Which of the following are legal Java identifiers.
    hello		  count		 5times		int		 pepper2        while
    
    iden_tifier	  APPLES	 &*(            do-it            if             else    
    
  14. Deep thought of the day. The volume of a cylinder of radius r and height h is πr2h. Think of a pizza as being a short cylinder with radius z and height a. Complete the Java code segment below to compute the volume of a pizza that has a 12 inch radius and is 1/2 an inch thick..
        double pi,a,z,volume;
        pi = 3.14159;
        z = 
        a = 
        volume =