Ask a Question
Send an email to me.
 
Java Question and Answer Forums
JavaRanch Big Moose Saloon
Marcus Green's Discussion Forum
java.sun.com Forums, Chat and User Groups
 
Other Resources
Java Language Specification
Java Virtual Machine Specification
Java 2 Platform, Standard Edition, v 1.4.0 API Specification
 
Tutorials
Learning the Java Language
Operator Precedence Chart, Expressions, Statements, Blocks
Programming with Assertions
 
Answers: Certified Java Programmer Mock Exam
No.AnswerRemark
1Prints: FDDD  The method name abs is overloaded. There are versions that accept one argument of type int, long, float or double. The type of the return value is the same as the argument type. The sqrt method is not overloaded. The parameter type is double and the return type is double.  
2Prints: IIILFD  There are four overloaded versions of the Math.min method with versions that declare one parameter of type int, long, float or double. The return type is the same as the parameter type. Arguments of type byte, char and short are promoted to type int.  
3Prints: FDIL  The method name abs is overloaded. There are versions that accept one argument of type int, long, float or double. The type of the return value is the same as the argument type. There are two versions of the Math.round method. One accepts an argument of type float; the return type is int. The other accepts an argument of type double; the return type is long.  
4round   
5None of the above   
6None of the above   
7The returned value is of type long only if the argument is of type double 
8Adds 0.5 to the argument and takes the floor of the result.   
9None of the above  If the java.lang.Math.round method is invoked with an argument of the float type and the result exceeds the range of type int, then the result is Integer.MAX_VALUE.  
10It is not overloaded.  The argument and returned value are both of type double. If the argument is negative, then the returned value is NaN.  
11a  c  It is not overloaded.  The argument is an angle measured in radians.  The argument is of type double and represents an angle measured in radians. The returned value is of type double. The method does not throw any exceptions.  
12None of the above  The random method is not overloaded, does not declare any parameters and does not throw any exceptions. The returned value is greater than or equal to zero and is less than but not equal to one.  
13Returns the largest whole number that is less than or equal to the argument value.  The floor method is not overloaded, and declares only one parameter of type double. The return value is always of type double. The floor method does not declare any exceptions.  
14Returns the smallest whole number that is greater than or equal to the argument value.  The ceil method is not overloaded, and declares only one parameter of type double. The return value is always of type double. The ceil method does not declare any exceptions.  
15a  c  f  Four overloaded versions of abs exist.  The type of the return value depends on the argument type.  If the argument is positive, then the argument is returned.  The method name abs is overloaded. There are versions that accept one argument of type int, long, float or double. The type of the return value is the same as the argument type. No exceptions are declared. If the argument is a negative integral value, then the returned value is the two's complement of the argument. The magnitude of Integer.MIN_VALUE is one greater than the magnitude of Integer.MAX_VALUE; therefore, the absolute value of Integer.MIN_VALUE exceeds the range of Integer.MAX_VALUE. Due to the limited range of type int, the two's complement of Integer.MIN_VALUE is Integer.MIN_VALUE. For that reason, the Math.abs method returns Integer.MIN_VALUE when the argument is Integer.MIN_VALUE.  
16b  c  e  f  h  Positive infinity  NaN  Integer.MIN_VALUE  Long.MIN_VALUE  Positive zero  The method name abs is overloaded. There are versions that accept one argument of type int, long, float or double. The type of the return value is the same as the argument type. The result is positive infinity if the argument is negative infinity. The result is positive zero if the argument is negative zero. The result is NaN if the argument is NaN. If the argument is a negative integral value, then the returned value is the two's complement of the argument. The magnitude of Integer.MIN_VALUE is one greater than the magnitude of Integer.MAX_VALUE; therefore, the absolute value of Integer.MIN_VALUE exceeds the range of Integer.MAX_VALUE. Due to the limited range of type int, the two's complement of Integer.MIN_VALUE is Integer.MIN_VALUE. For that reason, the Math.abs method returns Integer.MIN_VALUE when the argument is Integer.MIN_VALUE. The negation of Short.MIN_VALUE is well within the range of type int; so Short.MIN_VALUE is never returned by the Math.abs method.  
17Prints: -4.0,-3.0,3.0,4.0  The Math.floor method returns a primitive of type double that is equal to the largest integral value that is smaller than or equal to the argument. For example, -4.0 is the floor of -3.6, because -4.0 is the largest floating-point value tthat is equal to an integral value that is closer to negative infinity than -3.6. Similarly, the Math.ceil method returns a primitive of type double that is equal to an integral value, and is smaller than any other such value that is larger than the argument. For example, -3.0 is the ceil of -3.6. The term "larger" refers to values that are closer to positive infinity. For example, -3 is larger than -4, because -3 is closer to positive infinity.  
18None of the above  The math.round method name is overloaded. If the argument is of type double, then the return value is of type long. If the argument is of type float, then the return value is of type int. Both return types are integral primitive types; so a decimal point should not be included in the output. The actual output is -4,-3,3,4.  
19Prints: 0,0  The math.round method adds 0.5 to the argument, and then takes the floor of the sum. The result of Math.round with an argument of -3.6 is -4. The result of Math.round with an argument of 3.6 is 4.0. The sum of the two results is zero.  

Copyright © 2002-2003, Dan Chisholm
All rights reserved.