Java The Complete Reference, Seventh Edition

(Greg DeLong) #1
Method Description
static double copySign(doublearg,
doublesignarg)

Returnsargwith same sign as that ofsignarg.
(Added by Java SE 6.)
static float copySign(floatarg,
floatsignarg)

Returnsargwith same sign as that ofsignarg.
(Added by Java SE 6.)
static int getExponent(doublearg) Returns the base-2 exponent used by the binar y
representation ofarg. (Added by Java SE 6.)
static int getExponent(floatarg) Returns the base-2 exponent used by the binar y
representation ofarg. (Added by Java SE 6.)
static double
IEEEremainder(doubledividend,
doubledivisor)

Returns the remainder ofdividend/divisor.

static hypot(doubleside1, doubleside2) Returns the length of the hypotenuse of a right
triangle given the length of the two opposing sides.
static double random( ) Returns a pseudorandom number between 0 and 1.
static float signum(doublearg) Determines the sign of a value. It returns 0 ifargis 0,
1ifargis greater than 0, and –1 ifargis less than 0.
static float signum(floatarg) Determines the sign of a value. It returns 0 ifargis 0,
1ifargis greater than 0, and –1 ifargis less than 0.
static double toDegrees(doubleangle) Converts radians to degrees. The angle passed to
anglemust be specified in radians. The result in
degrees is returned.
static double toRadians(doubleangle) Converts degrees to radians. The angle passed to
anglemust be specified in degrees. The result in
radians is returned.

The following program demonstratestoRadians() andtoDegrees( ):

// Demonstrate toDegrees() and toRadians().
class Angles {
public static void main(String args[]) {
double theta = 120.0;


System.out.println(theta + " degrees is " +
Math.toRadians(theta) + " radians.");

theta = 1.312;
System.out.println(theta + " radians is " +
Math.toDegrees(theta) + " degrees.");
}
}


The output is shown here:


120.0 degrees is 2.0943951023931953 radians.
1.312 radians is 75.17206272116401 degrees.

Chapter 16: Exploring java.lang 421

Free download pdf