From aac7b7b91b54407a9d89b6d02d2153d3995810cf Mon Sep 17 00:00:00 2001 From: Kevin Date: Sat, 2 Sep 2023 18:12:28 -0700 Subject: [PATCH] completed assignment 2 --- .idea/misc.xml | 2 +- src/ArchimedesPiMethod.java | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index d15472f..045943f 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..9839e74 100644 --- a/src/ArchimedesPiMethod.java +++ b/src/ArchimedesPiMethod.java @@ -1,7 +1,17 @@ import java.util.Scanner; - public class ArchimedesPiMethod { public static void main(String[] args) { + System.out.println("Input the number of sides"); + Scanner z = new Scanner(System.in); + int n = z.nextInt(); + + double b = 360.0 / n; + double a = b / 2; + double baseS = 2 * Math.sin(Math.toRadians(a)); + double perimeterP = n * baseS; + double pi = (perimeterP / 2); + + System.out.printf("The pi estimate is %f" ,pi); } }