Summary for 4/15/02

Lecture Summary for 211 on 4/15/02 -- Loop Section

 

Review Questions

  1. What do you do if a line is too long in Java?
    Answer: Just break the line wherever you need to. Don't break the line in the middle of a variable name or constant.

  2. What do the following symbols mean in Java?
    +    *    /    .    %    !
    Answer: They are method selection, line terminator, begin block, string delimiter, start of comment, and contatenation, respectively.

  3. Rank these operators in order of highest to lowest precedence:
    -    /    =    ( )    &&    .    ==
    Answer:   ( )    .    /    -    ==    &&    =

  4. Write a line of java code to find the average of the four doubles a, b, c, d.   Answer:
    average = (a + b + c + d) / 2.0;

  5. What is the difference between static and nonstatic methods?
    Answer: A nonstatic method requires an object to execute it. A static method can be executed by either a class or an object.

  6. What import statement do you need to use an input dialog?   Answer:
    import javax.swing.JOptionPane;

  7. What is the output?
    int x = 4, y = 7;
    x += y * 2;
    y -= x - 3;
    System.out.print(x + " ");
    x /= 3;
    y = x;
    y /= 2;
    System.out.println(y);

    Output:18 3
    Here is the variable trace table:

    x y
    4 7
    18 7
    18 -8
    6 6
    3  

 

The DecimalFormat Class

 

The String Class

 

The Applet and Graphics Classes