6.35(幾何:五邊形的面積)五邊形的面積可以使用下面的公式計算:
撰寫一個方法,使用下面的方法頭來回傳五邊形的面積,
public static double area(double side)
撰寫一個主方法,提示用戶輸入五邊形的邊,然后顯示它的面積,
下面是一個運行示例:
Enter the side:5.5
The area of the pentagon is 52.044441
6.35(Geometry: area of a pentagon)The area of a pentagon can be computed using the following formula:
Write a method that returns the area of a pentagon using the following header:
public static double area(double side)
Write a main method that prompts the user to enter the side of a pentagon and displays its area.
Here is a sample run:
Enter the side:5.5
The area of the pentagon is 52.044441
下面是參考答案代碼:
// https://cn.fankuiba.com
import java.util.Scanner;
public class Ans6_35_page205 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the side: ");
double side = input.nextDouble();
System.out.println("The area of the pentagon is "+area(side));
}
public static double area(double side) {
return (5 * side * side) / (4 * Math.tan(Math.PI / 5));
}
}
適用Java語言程式設計與資料結構(基礎篇)(原書第11版)Java語言程式設計(基礎篇)(原書第10/11版)更多
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/183589.html
標籤:Java
