Write a Java program to compute the area of a polygon
- برمجة
- برمجة جافا
- 2021-05-01
- razanmazen8711884270
الأجوبة
import java.util.Scanner;
public class Exercise35 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Input the number of sides on the polygon: ");
int ns = input.nextInt();
System.out.print("Input the length of one of the sides: ");
double side = input.nextDouble();
System.out.print("The area is: " + polygonArea(ns, side)+"\n");
}
public static double polygonArea(int ns, double side) {
return (ns * (side * side)) / (4.0 * Math.tan((Math.PI / ns)));
}
}
Sample Output:
Input the number of sides on the polygon: 7 Input the length of one of the sides: 6 The area is: 130.82084798405722
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال