Java Reference
In-Depth Information
7
System.out.printf(
"Math.abs(23.7) = %f%n"
, Math.abs(
23.7
));
8
System.out.printf(
"Math.abs(0.0) = %f%n"
, Math.abs(
0.0
));
9
System.out.printf(
"Math.abs(-23.7) = %f%n"
, Math.abs(
-23.7
));
10
System.out.printf(
"Math.ceil(9.2) = %f%n"
, Math.ceil(
9.2
));
11
System.out.printf(
"Math.ceil(-9.8) = %f%n"
, Math.ceil(
-9.8
));
12
System.out.printf(
"Math.cos(0.0) = %f%n"
, Math.cos(
0.0
));
13
System.out.printf(
"Math.exp(1.0) = %f%n"
, Math.exp(
1.0
));
14
System.out.printf(
"Math.exp(2.0) = %f%n"
, Math.exp(
2.0
));
15
System.out.printf(
"Math.floor(9.2) = %f%n"
, Math.floor(
9.2
));
16
System.out.printf(
"Math.floor(-9.8) = %f%n"
, Math.floor(
-9.8
));
17
System.out.printf(
"Math.log(Math.E) = %f%n"
, Math.log(
Math.E
));
18
System.out.printf(
"Math.log(Math.E * Math.E) = %f%n"
,
19
Math.log(
Math.E
*
Math.E
));
20
System.out.printf(
"Math.max(2.3, 12.7) = %f%n"
, Math.max(
2.3
,
12.7
));
21
System.out.printf(
"Math.max(-2.3, -12.7) = %f%n"
,
22
Math.max(
-2.3
,
-12.7
));
23
System.out.printf(
"Math.min(2.3, 12.7) = %f%n"
, Math.min(
2.3
,
12.7
));
24
System.out.printf(
"Math.min(-2.3, -12.7) = %f%n"
,
25
Math.min(
-2.3
,
-12.7
));
26
System.out.printf(
"Math.pow(2.0, 7.0) = %f%n"
, Math.pow(
2.0
,
7.0
));
27
System.out.printf(
"Math.pow(9.0, 0.5) = %f%n"
, Math.pow(
9.0
,
0.5
));
28
System.out.printf(
"Math.sin(0.0) = %f%n"
, Math.sin(
0.0
));
29
System.out.printf(
"Math.sqrt(900.0) = %f%n"
, Math.sqrt(
900.0
));
30
System.out.printf(
"Math.tan(0.0) = %f%n"
, Math.tan(
0.0
));
31
}
// end main
32
}
// end class MathTest
Math.abs(23.7) = 23.700000
Math.abs(0.0) = 0.000000
Math.abs(-23.7) = 23.700000
Math.ceil(9.2) = 10.000000
Math.ceil(-9.8) = -9.000000
Math.cos(0.0) = 1.000000
Math.exp(1.0) = 2.718282
Math.exp(2.0) = 7.389056
Math.floor(9.2) = 9.000000
Math.floor(-9.8) = -10.000000
Math.log(Math.E) = 1.000000
Math.log(Math.E * Math.E) = 2.000000
Math.max(2.3, 12.7) = 12.700000
Math.max(-2.3, -12.7) = -2.300000
Math.min(2.3, 12.7) = 2.300000
Math.min(-2.3, -12.7) = -12.700000
Math.pow(2.0, 7.0) = 128.000000
Math.pow(9.0, 0.5) = 3.000000
Math.sin(0.0) = 0.000000
Math.sqrt(900.0) = 30.000000
Math.tan(0.0) = 0.000000
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 declared within method
g
.
Correction: Move the declaration of
h
outside the declaration of
g
.
b)
Error: The method is supposed to return an integer, but does not.
Correction: Delete the 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;