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 1You need a method to take a double primitive value and return the square root, ignoring the sign of the input. Which one of these options is correct?
  • A.

    double mySqrt( double val ){
          return Math.sqrt( val );
    }
    
  • B.

    double mySqrt( double val ){
          return Math.sqrt( Math.abs( val ) ) ;
       }
    
  • C.

    double mySqrt( double val ){
          Math myM = new Math();
          return myM.sqrt( myM.abs( val )) ;
       }
    
  • D.

    public double mySqrt(double val){
      return Math.sqrt(Math.round(val));
    
      }
    
A1: Answer B is correct. It uses the Math static methods to take the absolute value of the input before passing it to the square root function. Answer A is incorrect because it does not take into account the possibility of a negative input. Answer C is incorrect because ...

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