Pre-Lab Assignment: Lab #2

  1. What is the difference between a variable and a constant?



  2. Explain what each of the lines below does. Be sure to indicate how each is different from the others.
    1. int x;


    2. int x = 3;


    3. x = 3;


  3. The following program reads three integers and prints the average. Fill in the blanks so that it will work correctly.
    
    // **********************************************
    // FILE: Average.java
    // Author: Adrienne Bloss
    //
    // Purpose: Read three integers from the user and print their average
    // **********************************************
    
    import cs1.Keyboard;
    public class Average
    {
      public static void main(String[] args)
      {
        int val1, val2, val3;
        double average;
    
        // get three values from user
        System.out.println("Please enter three integers and " +
                           "I will compute their average");
    
        ____________________________________
    
        ____________________________________
    
        ____________________________________
    
        //compute the average
    
        ____________________________________
    
        //print the average
    
        ____________________________________
    
      }
    
    }
    



  4. Given the declarations below, find the result of each expression.
    int a = 3, b = 10, c = 7;
    double w = 12.9, y = 3.2;
    
    1. a + b * c

    2. a - b - c

    3. a / b

    4. b / a

    5. a - b / c

    6. w / y

    7. y / w

    8. a + w / b

    9. a % b / y

    10. b % a

    11. w % y