From ff4f613136d4aa3a25d0c8403e6893ac248ef1e5 Mon Sep 17 00:00:00 2001 From: Rayman4009 Date: Sun, 3 Sep 2023 11:16:16 -0700 Subject: [PATCH 1/3] Why is it 0 --- .idea/codeStyles/Project.xml | 7 +++++++ .idea/codeStyles/codeStyleConfig.xml | 5 +++++ .idea/misc.xml | 2 +- src/ArchimedesPiMethod.java | 12 +++++++++--- 4 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/codeStyles/codeStyleConfig.xml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..919ce1f --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..a55e7a1 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index d15472f..501ce09 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..0c69ea2 100644 --- a/src/ArchimedesPiMethod.java +++ b/src/ArchimedesPiMethod.java @@ -1,7 +1,13 @@ -import java.util.Scanner; - +import java.lang.Math; public class ArchimedesPiMethod { public static void main(String[] args) { - + int n = 8; + int b = 360 / n; + int a = (1/2) * b; + double newA = Math.toRadians(a); + double s = 2 * Math.sin(newA); + double p = n * s; + double PI = p / 2; + System.out.println(PI); } } From 7d0d1c45971eccca0f3c747fd1d05230f32d31d5 Mon Sep 17 00:00:00 2001 From: Rayman4009 Date: Sun, 3 Sep 2023 12:09:37 -0700 Subject: [PATCH 2/3] Why is it 0 --- src/ArchimedesPiMethod.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ArchimedesPiMethod.java b/src/ArchimedesPiMethod.java index 0c69ea2..d1f2256 100644 --- a/src/ArchimedesPiMethod.java +++ b/src/ArchimedesPiMethod.java @@ -1,9 +1,9 @@ import java.lang.Math; public class ArchimedesPiMethod { public static void main(String[] args) { - int n = 8; - int b = 360 / n; - int a = (1/2) * b; + float n = 8; + float b = 360 / n; + float a = (1/2f) * b; double newA = Math.toRadians(a); double s = 2 * Math.sin(newA); double p = n * s; From 7b3383bc64eba609b17e1cc3ac262aeff7385ab4 Mon Sep 17 00:00:00 2001 From: Rayman4009 Date: Sun, 3 Sep 2023 12:11:19 -0700 Subject: [PATCH 3/3] Needed a 2.0 not a 2 --- src/ArchimedesPiMethod.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ArchimedesPiMethod.java b/src/ArchimedesPiMethod.java index d1f2256..0a1586b 100644 --- a/src/ArchimedesPiMethod.java +++ b/src/ArchimedesPiMethod.java @@ -3,7 +3,7 @@ public class ArchimedesPiMethod { public static void main(String[] args) { float n = 8; float b = 360 / n; - float a = (1/2f) * b; + double a = (1/2.0) * b; double newA = Math.toRadians(a); double s = 2 * Math.sin(newA); double p = n * s;