java语言程序设计基础篇第四章编程练习题

本文主要探讨Java语言第四章的编程练习,涵盖基础语法、数据类型和控制结构的应用,旨在提升初学者的编程能力。
摘要由CSDN通过智能技术生成
1

import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner input = new Scanner(System.in);
		double r = input.nextDouble();
		double s = 2*r*Math.sin(Math.PI/5);
		double area  = (5*Math.pow(s, 2))/(4*Math.tan(Math.PI/5));
		System.out.println(area);
	}
}

2

import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner input = new Scanner(System.in);
		double R = 6371.01;
		double x1 = input.nextDouble();
		x1 = Math.toRadians(x1);
		double y1 = input.nextDouble();
		y1 = Math.toRadians(y1);
		double x2 = input.nextDouble();
		x2 = Math.toRadians(x2);
		double y2 = input.nextDouble();
		y2 = Math.toRadians(y2);
		double distance = R*Math.acos(Math.sin(x1)*Math.sin(x2) + Math.cos(x1)*Math.cos(x2)*Math.cos(y1-y2));
		System.out.println(distance);
	}
}


3

这是个悲剧,给出的地图网址打不开,虽然百度地图也可以找到,但是我可真不想去美国地图上找城市,还要算经纬度,直接放弃这题了。

4

import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		System.out.print("Enter the side:");
		double side = input.nextDouble();
		double s = (6*side*side)/(4*Math.tan(Math.PI/6));
		System.out.println("The area of the hexagon is " + s);
	}
}

5

书上的公式给错了,正确公式:面积 = (n*s*s)/(4*tan(π/n))
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		System.out.print("Enter the number of sides:");
		int numberOfTheSide = input.nextInt();
		System.out.print("Enter the sides:");
		double side = input.nextDouble();
		double s = (numberOfTheSide*side*side)/(4*Math.tan(Math.PI/numberOfTheSide));
		System.out.println("The area of the ploygon is " + s);
	}
}

6

import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		double radius = 40.0;
		double radians = Math.random()*Math.PI*2;
		double x1 = radius * Math.cos(radians);
		double y1 = radius * Math.sin(radians);
		
		radians = Math.random()*Math.PI*2;
		double x2 = radius * Math.cos(radians);
		double y2 = radius * Math.sin(radians);
		
		radians = Math.random()*Math.PI*2;
		double x3 = radius * Math.cos(radians);
		double y3 = radius * Math.sin(radians);
		
		double sideA = Math.sqrt(Math.pow(x1-x2,2.0) + Math.pow(y1-y2, 2.0));
		double sideB = Math.sqrt(Math.pow(x1-x3,2.0) + Math.pow(y1-y3, 2.0));
		double sideC = Math.sqrt(Math.pow(x3-x2,2.0) + Math.pow(y3-y2, 2.0));
		
		double cosA = (sideB*sideB + sideC*sideC - sideA*sideA)/(2*sideB*sideC);
		double cosB = (sideA*sideA + sideC*sideC - sideB*sideB)/(2*sideA*sideC);
		double cosC = (sideB*sideB + sideA*sideA - sideC*sideC)/(2*sideB*sideA);
		
		System.out.println("cosA: " + Math.toDegrees(Math.acos(cosA)));
		System.out.println("cosB: " + Math.toDegrees(Math.acos(cosB)));
		System.out.println("cosC: " + Math.toDegrees(Math.acos(cosC)));
	}
}

7

import java.util.Scanner;
public class Main {
	
	public static void main
  • 4
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 10
    评论
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值