From a86e63cc3de928b8d481cfcf87e8c9e3df533b2d Mon Sep 17 00:00:00 2001 From: sjmeans Date: Sat, 23 Sep 2023 18:34:16 -0700 Subject: [PATCH] assignment completed --- .idea/misc.xml | 2 +- src/ArchimedesPiMethod.java | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) 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