diff --git a/.idea/misc.xml b/.idea/misc.xml index d15472f..844b5c4 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/src/ArchimedesPiMethod.java b/src/ArchimedesPiMethod.java index 0b6e780..826fd56 100644 --- a/src/ArchimedesPiMethod.java +++ b/src/ArchimedesPiMethod.java @@ -2,6 +2,20 @@ public class ArchimedesPiMethod { public static void main(String[] args) { - + while(true){ + System.out.print("Please input the amount of sides in your desired polygon: "); + Scanner sc = new Scanner(System.in); + int n = sc.nextInt(); + if(n < 1) { + System.out.println("Cheeky, try again."); + break; + } + System.out.printf("You chose a polygon of %d sides.\n", n); + double b = 360.0 / n; + double a = b / 2; + double s = 2 * Math.sin(Math.toRadians(a)); + double p = n * s; + System.out.println("You've calculated an estimation of pi resulting to: " + p / 2.0 + ", close, but no cigar!"); + } } -} +} \ No newline at end of file