4.1

import java.util.Scanner;

public class Welcome
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter the length from the center to a vertex:");
double r = input.nextDouble();
double s = 2 * r * Math.sin(Math.PI / 5);
double area = 5 * s * s / (4 * Math.tan(Math.PI / 5));
System.out.printf("The area of the pentagon is %.2f",area);
}
}

4.2

import java.util.Scanner;

public class Welcome
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter point 1(latitude and longitude) in degrees:");
double deX1 = input.nextDouble(),deY1 = input.nextDouble();
System.out.print("Enter point 2(latitude and longitude) in degrees:");
double deX2 = input.nextDouble(),deY2 = input.nextDouble();
double x1 = Math.toRadians(deX1),y1 = Math.toRadians(deY1);
double x2 = Math.toRadians(deX2),y2 = Math.toRadians(deY2);
final double r = 6371.01;
double d = r * Math.acos(Math.sin(x1) * Math.sin(x2) + Math.cos(x1) * Math.cos(x2) * Math.cos(y1 - y2));
System.out.println("The distance between the two points is "+d+" km");
}
}

4.3

4.4

import java.util.Scanner;

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

4.5

import java.util.Scanner;

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

4.6

  

  

  

  

java语言程序设计与数据结构(基础篇)第四章答案的更多相关文章

  1. Java语言程序与数据结构(基础篇)-随记

    有关代码见BasicJava U1-Java概述 1-程序设计风格和文档 1.注释风格 注释:// ; 块注释:/* ~ / ; javadoc注释:/* ~ */ javadoc注释 eg. /** ...

  2. Java语言程序设计(基础篇) 第四章 数学函数、字符和字符串

    第四章 数学函数.字符和字符串 4.2 常用数学函数 方法分三类:三角函数方法(trigonometric method).指数函数方法(exponent method)和服务方法(service m ...

  3. Java语言程序设计与数据结构(基础篇)第七章答案

    答案为本人求解,如有错误,还望海涵.如有雷同,纯属巧合. 7.1 import java.util.Scanner; public class Main { public static void ma ...

  4. java语言程序设计与数据结构(基础篇)第二章答案

    答案为本人自己求解,若有错误,还望海涵并及时告知.如有雷同,纯属巧合. 2.1 import java.util.Scanner; public class Welcome { public stat ...

  5. Java编程基础篇第四章

    循环结构 循环结构的分类 for循环,while循环,do...while()循环 for循环 注意事项: a:判断条件语句无论简单还是复杂结果是boolean类型 b:循环体语句如果是一条语句,大括 ...

  6. Java语言程序设计(第三版)第二章课后习题答案(仅供参考)

    2.1   注意不同类型转换 import java.util.Scanner; public class Ch02 { public static void main(String[] args) ...

  7. 明解C语言 入门篇 第四章答案

    练习4-1 #include <stdio.h> int main(void) { int no; int x; do{ printf("请输入一个整数:"); sca ...

  8. 明解C语言 中级篇 第四章答案

    练习4-1 /* 珠玑妙算 */ #include <time.h> #include <ctype.h> #include <stdio.h> #include ...

  9. Java语言程序设计-助教篇

    1. 给第一次上课(软件工程)的老师与助教 现代软件工程讲义 0 课程概述 给学生:看里面的第0个作业要求 2. 助教心得 美国视界(1):第一流的本科课堂该是什么样?(看里面的助教部分) 助教工作看 ...

随机推荐

  1. ScheduledExecutorService中scheduleAtFixedRate方法与scheduleWithFixedDelay方法的区别

    ScheduledExecutorService中scheduleAtFixedRate方法与scheduleWithFixedDelay方法的区别 ScheduledThreadPoolExecut ...

  2. 阿里云(CentOS)搭建MediaWiki

    搭建环境 系统:CentOS 7.3 PHP:5.4.16 Mysql:maria MediaWiki:1.26.4(更高版本不再支持PHP5.4) 下面我们开始安装LAMP环境: 1.安装Apach ...

  3. rollup 使用babel7版本的插件rollup-plugin-babel,rollup-plugin-babel使用报错解决办法。

    最近在研究rollup,想吐槽下rollup的官方文档写的真的太简单了,而且照着文档一步步来还报错,说明文档年代有点久远啊... 照着文档使用rollup-plugin-babel报错,首先打开rol ...

  4. struts2拦截action多种方法

    按照教程写的,运行的时候显示There is no Action mapped for namespace [/] and action name [login!method1] associated ...

  5. Android Jetpack基本架构之ViewModel+LiveData+DataBinding入门

    前提:导入所有依赖,开启DataBinding app的build.gradle android { defaultConfig { ... dataBinding { enabled true } ...

  6. (五)羽夏看C语言——结构体与类

    写在前面   由于此系列是本人一个字一个字码出来的,包括示例和实验截图.本人非计算机专业,可能对本教程涉及的事物没有了解的足够深入,如有错误,欢迎批评指正. 如有好的建议,欢迎反馈.码字不易,如果本篇 ...

  7. JUnit5快速入门指南-2

    重复测试中容易产生的问题 //结果类 private static int result = 0; public static int count(int x) throws InterruptedE ...

  8. Linux 动态库的编译和使用

    1. 动态链接库简介 动态库又叫动态链接库,是程序运行的时候加载的库,当动态链接库正确安装后,所有的程序都可以使用动态库来运行程序.动态库是目标文件的集合,目标文件在动态库中的组织方式是按特殊的方式组 ...

  9. Nginx:常用基本命令与异常处理

    Nginx日志 - ./nginx-1.6.0-ems/logs/nginx.pid Nginx启动时应该使用cmd等命令行工具启动,双击启动同样会产生进程但会造成异常,判断条件是 ./nginx-1 ...

  10. IIS中配置WCF站点

    http://msdn.microsoft.com/zh-cn/library/aa751852.aspx http://blog.csdn.net/hsg77/article/details/389 ...