Java Reference
In-Depth Information
35 Math.round(B * 100 ) / 100 . 0 + " " +
36 Math.round(C * 100 ) / 100 . 0 );
37 }
38 }
Enter three points: 1 1 6.5 1 6.5 2.5
The three angles are 15.26 90.0 74.74
The program prompts the user to enter three points (line 8). This prompting message
is not clear. You should give the user explicit instructions on how to enter these points as
follows:
System.out.print( "Enter the coordinates of three points separated "
+ "by spaces like x1 y1 x2 y2 x3 y3: " );
Note that the distance be tween two points (x1, y1) and (x2, y2) can be com-
puted using the formula
y 1 ) 2 . The program computes the dis-
tances between two points (lines 17-22), and applies the formula to compute the angles
(lines 25-30). The angles are rounded to display up to two digits after the decimal point
(lines 34-36).
The Math class is used in the program, but not imported, because it is in the java.
lang package. All the classes in the java.lang package are implicitly imported in a Java
program.
x 1 ) 2
2
( x 2
-
+
( y 2
-
4.1
Evaluate the following method calls:
Check
Point
(a) Math.sqrt( 4 )
(b) Math.sin( 2 * Math.PI)
(c) Math.cos( 2 * Math.PI)
(d) Math.pow( 2 , 2 )
(e) Math.log(Math.E)
(f) Math.exp( 1 )
(g) Math.max( 2 , Math.min( 3 , 4 ))
(h) Math.rint( -2.5 )
(i) Math.ceil( -2.5 )
(j) Math.floor( -2.5 )
(k) Math.round( -2.5f )
(l) Math.round( -2.5 )
(m) Math.rint( 2.5 )
(n) Math.ceil( 2.5 )
(o) Math.floor( 2.5 )
(p) Math.round( 2.5f )
(q) Math.round( 2.5 )
(r) Math.round(Math.abs( -2.5 ))
4.2
True or false? The argument for trigonometric methods is an angle in radians.
4.3
Write a statement that converts 47 degrees to radians and assigns the result to a
variable.
4.4
Write a statement that converts π / 7 to an angle in degrees and assigns the result
to a variable.
4.5
Write an expression that obtains a random integer between 34 and 55 . Write an
expression that obtains a random integer between 0 and 999 . Write an expression
that obtains a random number between 5.5 and 55.5 .
4.6
Why does the Math class not need to be imported?
4.7
What is Math.log(Math.exp(5.5)) ? What is Math.exp(Math.log(5.5)) ?
What is Math.asin(Math.sin(Math.PI / 6)) ? What is Math.sin(Math.
asin(Math.PI / 6)) ?
 
Search WWH ::




Custom Search