From bb6c19406d5210940f513baacc46cae8c0f4417e Mon Sep 17 00:00:00 2001 From: CMENG92 Date: Sat, 2 Sep 2023 15:24:00 -0700 Subject: [PATCH] Second Assignment complete! Produced a method to solve Archimedes PI Method! -Cameron Meng. --- .idea/misc.xml | 2 +- src/ArchimedesPiMethod.java | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index d15472f..07115cd 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..d9882a1 100644 --- a/src/ArchimedesPiMethod.java +++ b/src/ArchimedesPiMethod.java @@ -1,7 +1,28 @@ +/** + * + * @author Trevor Hartman + * @author Cameron Meng + * + * + */ import java.util.Scanner; 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: %f%n", pi); + System.out.println(pi); +} } }