From 814ea531ad095a3ec2ddebcd827f24fc03acb122 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Sat, 2 Sep 2023 22:28:52 -0700 Subject: [PATCH] Followed video because math is math. Working Pi estimation. --- .idea/misc.xml | 1 - src/ArchimedesPiMethod.java | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index d15472f..116ab47 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,3 @@ - diff --git a/src/ArchimedesPiMethod.java b/src/ArchimedesPiMethod.java index 0b6e780..368b671 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.println("Please type the number 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); + } } }