Review Questions

graphics/rq_icon.gif

10.10

Given the following program, which lines will print 11 exactly?

class MyClass {
    public static void main(String[] args) {
        double v = 10.5;

        System.out.println(Math.ceil(v));        // (1)
        System.out.println(Math.round(v));       // (2)
        System.out.println(Math.floor(v));       // (3)
        System.out.println((int) Math.ceil(v));  // (4)
        System.out.println((int) Math.floor(v)); // (5)
    }
}

Select the two correct answers.

  1. The line labeled (1).

  2. The line labeled (2).

  3. The line labeled (3).

  4. The line labeled (4).

  5. The line labeled (5).

10.11

Which method is not defined in the Math class?

Select the one correct answer.

  1. double tan2(double)

  2. double cos(double)

  3. int abs(int a)

  4. double ceil(double)

  5. float max(float, float)

10.12

What is the return type of the method round(float) from the Math class?

Select the one correct answer.

  1. int

  2. float

  3. double

  4. Integer

  5. Float

10.13

What is the return type of the method ceil(double) from the Math class?

Select the one correct answer.

  1. int

  2. float

  3. double

  4. Integer

  5. Double

10.14

What will the following program print when run?

public class Round {
    public static void main(String[] args) {
        System.out.println(Math.round(-0.5) + " " + Math.round(0.5));
    }
};

Select the one correct answer.

  1. 0 0

  2. 0 1

  3. -1 0

  4. -1 1

  5. None of the above.

10.15

Which statements are true about the expression ((int)(Math.random()*4))?

Select the three correct answers.

  1. It may evaluate to a negative number.

  2. It may evaluate to the number 0.

  3. The probability of it evaluating to the number 1 or the number 2 is the same.

  4. It may evaluate to the number 3.

  5. It may evaluate to the number 4.