From e80b6811d1abf608b63e3569e255255fbf0aadd8 Mon Sep 17 00:00:00 2001 From: Joseph Verdin Date: Sat, 23 Sep 2023 23:52:20 -0700 Subject: [PATCH] Completed Assignment 002 --- .idea/misc.xml | 2 +- src/ArchimedesPiMethod.java | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index d15472f..cf9abe6 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..253e8da 100644 --- a/src/ArchimedesPiMethod.java +++ b/src/ArchimedesPiMethod.java @@ -2,6 +2,19 @@ public class ArchimedesPiMethod { public static void main(String[] args) { - + while(true) { + System.out.println("Type # of sides"); + Scanner sc = new Scanner(System.in); + int n = sc.nextInt(); + if(n < 1) { + break; + } + double b = 360.0/n; + double a = b / 2; + double s = 2 * Math.sin(Math.toRadians(a)); + double p = n * s; + double pi = p / 2; + System.out.printf(" Our PI estimate is: %.10f%n", pi); + } } }