Review Exercises (Set A1)

  1. String word = "CS170 abcd"; 
    int i = 4; 
    int j = 20; 
    char c = 'd';
    

    Assuming the above declarations and assignments have been made, give a literal of the correct type that is equivalent (in the "==" sense) to each of the following:

  2. Name the 6 numerical primitive data types in Java, and identify those whose values are stored only approximately in memory.  

    the six numerical primitive types: byte, short, int, long, float, double
    those stored approximately: float, double

  3. Which of the following are legal names for variables in Java?

    1. 1stNum
    2. num1
    3. myChar_
    4. $tempBoolean
    5. while

     
    (b), (c), and (d); (the first choice is illegal as you can't start a variable name with a digit, the last is illegal as "while" is a reserved word)
  4. Convert $-0.3$ to 32-bit IEEE-754 form.  

    1 0111110 100110011001100110011010

  5. Write a truth table for the following expression: (P ^ Q) && (! (P || R))  

    P   Q   R   P^Q   P||R   !(P||R)   (P^Q)&&(!(P||R))
    T   T   T    F      T      F              F
    T   T   F    F      T      F              F
    T   F   T    T      T      F              F
    T   F   F    T      T      F              F
    F   T   T    T      T      F              F
    F   T   F    T      F      T              T
    F   F   T    F      T      F              F
    F   F   F    F      F      T              F