Java Reference
In-Depth Information
Here,
s
is the length of a side. Write a program that prompts the user to enter the
number of sides and their length of a regular polygon and displays its area. Here is
a sample run:
Enter the number of sides: 5
Enter the side: 6.5
The area of the polygon is 74.69017017488385
*4.6
(
Random points on a circle
) Write a program that generates three random points
on a circle centered at (0, 0) with radius 40 and display three angles in a triangle
formed by these three points, as shown in Figure 4.7a. (Hint: Generate a random
angle
, as shown in Figure 4.7b and the point deter-
mined by this angle is (r*cos(
a
), r*sin(
a
)).)
a
in radians between 0 and 2
p
x
=
r
×
cos(
α
) and
y
=
r
×
sin(
α
)
0 o'clock position
p
2
(
x
,
y
)
60
r
p
3
p
1
r
65
α
(0, 0)
55
p
4
p
5
(a)
(b)
(c)
F
IGURE
4.7
(a) A triangle is formed from three random points on the circle. (b) A random
point on the circle can be generated using a random angle
a
. (c) A pentagon is centered at
(0, 0) with one point at the 0 o'clock position.
*4.7
(
Corner point coordinates
) Suppose a pentagon is centered at (0, 0) with one point
at the 0 o'clock position, as shown in Figure 4.7c. Write a program that prompts
the user to enter the radius of the bounding circle of a pentagon and displays the
coordinates of the five corner points on the pentagon. Here is a sample run:
Enter the radius of the bounding circle: 100
The coordinates of five points on the pentagon are
(95.1057, 30.9017)
(0.000132679, 100)
(-95.1056, 30.9019)
(-58.7788, -80.9015)
(58.7782, -80.902)
Sections 4.3-4.6
*4.8
(
Find the character of an ASCII code
) Write a program that receives an ASCII code
(an integer between
0
and
127
) and displays its character. Here is a sample run:
Enter an ASCII code: 69
The character for ASCII code 69 is E
Search WWH ::
Custom Search