Joined: Fri Oct 16, 2009 8:54 pm Posts: 126
|
Consider the following class:
public class TestSample private ArrayList samples;
public TestSample(int n) for (int k = 0; k < n; k++) samples.add(k);
public double getBestRatio() double maxRatio = samples.get(1).intValue() / samples.get(0).intValue();
for (int k = 1; k < samples.size() - 1; k++) double ratio = samples.get(k+1).intValue() / samples.get(k).intValue(); if (ratio > maxRatio) maxRatio = ratio; return maxRatio;
What is the result of the following code segment?
TestSample t = new TestSample(1); System.out.println(t.getBestRatio());
A. NullPointerException
B. ArithmeticException
C. IndexOutOfBoundsException
D. ClassCastException
E. Infinity
|
|