Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/ArchimedesPiMethod.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
/**
*
* @author Trevor Hartman
* @author Miranda Arnett
*
* @since Version 1.0
*
*/

import java.util.Scanner;

public class ArchimedesPiMethod {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
while (true) {
System.out.print("Please enter the number of sides for a polygon: ");
int numSides = Integer.parseInt(s.nextLine());
if (numSides == -1) {
break;
}
double B = 360.0 / numSides;
double A = B / 2;
double side = 2 * Math.sin(Math.toRadians(A));
double p = numSides * side;
double myPI = p / 2;
System.out.printf("My estimate for PI: %.15f Real PI: %.15f", myPI, Math.PI);
System.out.println();
}


}
}