fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. RegularPolygon poly = new RegularPolygon(4, 10);
  13. System.out.println(poly.getr());
  14. }
  15.  
  16. public static class RegularPolygon {
  17. private int numSides; //# sides
  18. private double sideLength; //side length
  19. private double inscribedRadius; //radius of inscribed circle
  20.  
  21. public RegularPolygon(int numSides, double sideLength) {
  22. this.numSides = numSides;
  23. this.sideLength = sideLength;
  24. this.calcr();
  25. }
  26.  
  27. private void calcr(){
  28. inscribedRadius = .5 * sideLength * 1/Math.tan(Math.PI / numSides);
  29. }
  30.  
  31. public double getr(){
  32. return inscribedRadius;
  33. }
  34. }
  35. }
Success #stdin #stdout 0.08s 380160KB
stdin
Standard input is empty
stdout
5.000000000000001