nerdexam
Oracle

1Z0-819 · Question #190

1Z0-819 Question #190: Real Exam Question with Answer & Explanation

Sign in or unlock 1Z0-819 to reveal the answer and full explanation for question #190. The question stem and answer options stay visible for context.

Question

Which method throws an exception for not-a-number and infinite input values?```java // A static float validate1(String s, float min, float max) throws IllegalArgumentException { return Float.parseFloat(s); } // B static float validate2(String s, float min, float max) throws IllegalArgumentException { float f = Float.parseFloat(s); if (Float.isNaN(f) || f < min || f > max) { throw new IllegalArgumentException(); } return f; } // C static float validate3(String s, float min, float max) throws IllegalArgumentException { float f = Float.parseFloat(s); if (Float.isNaN(f) || f == Float.POSITIVE_INFINITY || f == Float.NEGATIVE_INFINITY || f < min || f > max) { throw new IllegalArgumentException(); } return f; } // D static float validate4(String s, float min, float max) throws IllegalArgumentException { float f = Float.parseFloat(s); if (Float.isInfinite(f) || f < min || f > max) { throw new IllegalArgumentException(); } return f; }```

Options

  • A// A static float validate1(String s, float min, float max) throws IllegalArgumentException { return Float.parseFloat(s); }
  • B// B static float validate2(String s, float min, float max) throws IllegalArgumentException { float f = Float.parseFloat(s); if (Float.isNaN(f) || f < min || f > max) { throw new IllegalArgumentException(); } return f; }
  • C// C static float validate3(String s, float min, float max) throws IllegalArgumentException { float f = Float.parseFloat(s); if (Float.isNaN(f) || f == Float.POSITIVE_INFINITY || f == Float.NEGATIVE_INFINITY || f < min || f > max) { throw new IllegalArgumentException(); } return f; }
  • D// D static float validate4(String s, float min, float max) throws IllegalArgumentException { float f = Float.parseFloat(s); if (Float.isInfinite(f) || f < min || f > max) { throw new IllegalArgumentException(); } return f; }

Unlock 1Z0-819 to see the answer

You've previewed enough free 1Z0-819 questions. Unlock 1Z0-819 for full answers, explanations, the timed quiz mode, progress tracking, and the master PDF. Question stem and options stay visible so you can still see what's on the exam.

Full 1Z0-819 Practice