问题及代码:
输入 number 和side 输出面积。
import java.util.Scanner;
public class MyTriangle {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out
.println("please enter the number of sides and the side of a regular polygon: ");
Scanner input = new Scanner(System.in);
int number = input.nextInt();
int side = input.nextInt();
double are = area(number, side);
System.out.println("the area is " + are);
}
public static double area(int n, double side) {
double area = (n * side * side) / (4 * Math.tan(3.1415926535 / n));
return area;
}
}
运行结果: