Frontpage web hosting - Chapter 6 Methods 303 39 System.out.println( “Math.pow( 2,

Chapter 6 Methods 303 39 System.out.println( “Math.pow( 2, 7 ) = ” + 40 Math.pow( 2, 7 ) ); 41 System.out.println( “Math.pow( 9, .5 ) = ” + 42 Math.pow( 9, .5 ) ); 43 System.out.println( “Math.sin( 0.0 ) = ” + 44 Math.sin( 0.0 ) ); 45 System.out.println( “Math.sqrt( 25.0 ) = ” + 46 Math.sqrt( 25.0 ) ); 47 System.out.println( “Math.tan( 0.0 ) = ” + 48 Math.tan( 0.0 ) ); 49 } 50 } Math.abs( 23.7 ) = 23.7 Math.abs( 0.0 ) = 0 Math.abs( -23.7 ) = 23.7 Math.ceil( 9.2 ) = 10 Math.ceil( -9.8 ) = -9 Math.cos( 0.0 ) = 1 Math.exp( 1.0 ) = 2.71828 Math.exp( 2.0 ) = 7.38906 Math.floor( 9.2 ) = 9 Math.floor( -9.8 ) = -10 Math.log( 2.718282 ) = 1 Math.log( 7.389056 ) = 2 Math.max( 2.3, 12.7 ) = 12.7 Math.max( -2.3, -12.7 ) = -2.3 Math.min( 2.3, 12.7 ) = 2.3 Math.min( -2.3, -12.7 ) = -12.7 Math.pow( 2, 7 ) = 128 Math.pow( 9, .5 ) = 3 Math.sin( 0.0 ) = 0 Math.sqrt( 25.0 ) = 5 Math.tan( 0.0 ) = 0 6.4 a) double hypotenuse( double side1, double side2 ) b) int smallest( int x, int y, int z ) c) void instructions() d) float intToFloat( int number ) 6.5 a) Error: Method h is defined in method g. Correction: Move the definition of h outside the definition of g. b) Error: The method is supposed to return an integer, but does not. Correction: Delete variable result, and place the statement return x + y; in the method, or add the following statement at the end of the method body: return result; c) Error: The result of n + sum(n-1) is not returned by this recursive method, resulting in a syntax error. Correction: Rewrite the statement in the else clause as return n + sum( n - 1); Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/3/01

Leave a Reply