Java语言程序设计(基础篇)第十版 4.7

本篇博客详细介绍了如何使用Java程序计算并打印出五边形五个顶点的坐标,通过用户输入圆的半径,利用三角函数精确计算各点位置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


public class J4_7 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		java.util.Scanner input = new java.util.Scanner(System.in);
		System.out.print("Enter the radius of the bounding circle:");
		
		double radius = input.nextDouble();
		
		double x2 = 0;
		double y2 = 100;
		
		double x3 = Math.cos(Math.PI/10)*(-1)*radius;
		double y3 = Math.sin(Math.PI/10)*radius;
		
		double x1 = Math.cos(Math.PI/10)*radius;
		double y1 = Math.sin(Math.PI/10)*radius;

		double x4=Math.cos((3*Math.PI)/10)*(-1)*radius;
	    double y4=Math.sin((3*Math.PI)/10)*(-1)*radius;
	    
	    double x5=Math.cos((3*Math.PI)/10)*radius;
	    double y5=y4;
        
		
		System.out.println("The coordinates of five point on the pentagon are:");
		System.out.println("("+x1+","+y1+")");
		System.out.println("("+x2+","+y2+")");
		System.out.println("("+x3+","+y3+")");
		System.out.println("("+x4+","+y4+")");
		System.out.println("("+x5+","+y5+")");
		
		

	}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值