//Polygons.java //radius fixed at 1, show apothem, side length, perimeter, area of regular polygons import java.awt.*; import javax.swing.*; import java.text.*; public class Polygons { public static void main (String[] args) { //String input; int angleSum, numDiags; double apothem, angle, area, perimeter, sideLen; double r=1.0; DecimalFormat d3 = new DecimalFormat ("0.000"); DecimalFormat d1 = new DecimalFormat ("0.0"); //input = JOptionPane.showInputDialog("Max value of k","16"); //maxTry = Integer.parseInt(input); System.out.println("n r a s p A angle anglesum diagonals"); for (int n=3; n<=12; n++) { apothem = r * Math.cos(Math.toRadians(180.0/n)); sideLen = 2 * (Math.sqrt(1 - apothem*apothem)); area = 0.5 * n * sideLen * apothem; perimeter = n * sideLen; numDiags = n * (n-3) / 2; angle = (1 - 2.0/n) * 180; angleSum = (n - 2) * 180; System.out.println(""+n+" "+r+" "+d3.format(apothem)+" "+d3.format(sideLen)+" "+ d3.format(perimeter)+" "+d3.format(area)+" "+ d1.format(angle)+" "+angleSum+" "+numDiags); } } }