Java语言程序设计基础篇第四章课后习题(保持更新)
2017-12-20 12:50
323 查看
1)五边形的面积
2)最大圆距离
4)六边形面积
8)给出字符的Unicode码
package com.Wyhon.test; import java.util.*; import java.text.*; public abstract class Rectangle { 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(); DecimalFormat df = new DecimalFormat("#.00"); System.out.println("The area of the pentagon is: " + df.format(GetArea(r))); } public static double GetArea(double r) { double frameLength = 2 * r * Math.sin(Math.PI / 5); double area = 5 * Math.pow(frameLength, 2) / (4 * Math.tan(Math.PI / 5)); return area; } }
2)最大圆距离
package com.Wyhon.test; import java.util.*; import java.text.*; public class Rectangle { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter point 1 (latitude and longitute) in degrees: "); String s1 = input.nextLine(); System.out.print("Enter point 2 (latitude and longitute) in degrees: "); String s2 = input.nextLine(); GetDistance(s1, s2); } public static void GetDistance(String s1, String s2) { final double r = 6371.01; String[] _s1 = s1.split(","); String[] _s2 = s2.split(","); double x1 = Math.toRadians(Double.parseDouble(_s1[0])); double y1 = Math.toRadians(Double.parseDouble(_s1[1])); double x2 = Math.toRadians(Double.parseDouble(_s2[0])); double y2 = Math.toRadians(Double.parseDouble(_s2[1])); double distance = 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 " + distance + " Km"); } }
4)六边形面积
package com.Wyhon.test; import java.util.Scanner; import java.text.*; public class test1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter the side: "); double s = input.nextDouble(); DecimalFormat df = new DecimalFormat("#.00"); System.out.println("The area of the hexagon is " + df.format(GetArea(s))); } public static double GetArea(double s) { double area = 6 * Math.pow(s, 2) / (4 * Math.tan(Math.PI / 6)); return area; } }
8)给出字符的Unicode码
package com.Wyhon.test; import java.util.Scanner; import java.text.*; public class test1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter a character: "); String str = input.next(); if(str.length() != 1) { System.out.println("You must enter an exact character!"); System.exit(1); } char ch = str.charAt(0); System.out.println("The Unicode for the character " + ch + " is " + (int) ch); } }
相关文章推荐
- Scala函数式编程课后习题答案(第四章)(更新ing)
- 《学习OpenCV》课后习题解答(第四章)(仅供参考)(不断更新)
- 《学习OpenCV》课后习题解答(第四章)(仅供参考)(不断更新)
- 教材第四章课后习题
- How to think like a Computer Scientist: 课后习题第四章 2题
- C++Primer Plus笔记——第四章 复合类型及课后习题答案
- Scala函数式编程课后习题答案(第三章)(更新ing)
- 第四章课后习题
- 鸟哥的linux私房菜基础学习篇课后习题与答案 第四章
- 数据结构与算法分析课后习题第四章(4)
- C++ primer plus 第四章课后习题
- 计算机操作系统第四版第四章课后习题答案
- 自考本科《计算机网络原理》课后习题参考答案(第四章)
- 谭浩强C语言程序设计课后习题解答(第四章)
- 计算机操作系统第四版第四章课后习题答案
- C++ Primer(第五版)课后习题记录 —— 第四章
- 《Python核心编程》 第四章 Python对象- 课后习题
- C++程序设计课后习题及解答(第四章)
- 《C++ Primer》第五版课后习题解答_第四章(2)(21-33)
- 陈国君java第五版第四章课后习题第五题