O'Reilly logo

Java 2™ Programmer Exam Cram™ 2 (Exam CX-310-035) by Marcus Green, Bill Brogden

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Exam Prep Practice Questions

Question 1 The following method is designed to convert an input string to a floating-point number while detecting a bad format (assume factor is a float variable defined elsewhere):
1. public boolean strCvt( String s ){
2.   try {
3.     factor =
          Float.valueOf( s ).floatValue();
4.     return true ;
5.   }catch(NumberFormatException e){
6.    System.out.println("Bad number " + s);
7.     factor = Float.NaN ;
8.   }finally { System.out.println("Finally");
9.   }
10.  return false ;
11. }

Which descriptions of the results of various inputs to the method are correct? [Check all correct answers.]

  • A. Input = “0.234”—Result: factor = 0.234, “Finally” is printed, true is returned.

  • B. Input = “0.234”—Result: factor = 0.234, “Finally” is printed, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required