第四章第七题(顶点坐标)(Corner point coordinates)
-
*4.7(顶点坐标)假设一个正五边形的中心位于(0,0),其中一个点位于0点位置。编写一个程序,提示用户输入正五边形外接圆的半径,以p1到p5的顺序显示正五边形上五个顶点的坐标。使用控制台格式来显示小数点后两位数字。
这里是一个运行示例:
Enter the radius of the bounding circle: 100.52
The coordinates of five points on the pentagon are
(95.60, 31.06)
(0.00, 100.52)
(-95.60, 31.06)
(-59.08, -81.32)
(59.08, -81.32)*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.4c. 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 from p1 to p5 in this order.Use console format to display two digits after the decimal point.
Here is a sample run:
Enter the radius of the bounding circle: 100.52
The coordinates of five points on the pentagon are
(95.60, 31.06)
(0.00, 100.52)
(-95.60, 31.06)
(-59.08, -81.32)
(59.08, -81.32) -
参考代码:
package chapter04;
import java.util.Scanner;
public class Code_07 {
public static void main(String[] args) {
double x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, radius;
Scanner inputScanner = new Scanner(System.in);