Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 21 additions & 2 deletions src/ArchimedesPiMethod.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
import java.util.Scanner;

public class ArchimedesPiMethod {
public static void main(String[] args) {

// Creates scanner object, intakes the next integer typed by user
Scanner scan = new Scanner(System.in);
System.out.print("Number of sides: ");
int numSides = scan.nextInt();
// Calculates value of angle B
int angleB = 360/numSides;
System.out.println("Angle B = " + angleB);
// Calculates value of angle A
double angleA = angleB * 0.5;
System.out.println("Angle A = " + angleA);
// Converts angle A to radians
double angleAR = Math.toRadians(angleA);
// Calculates value of triangle base s
double baseS = 2.0 * Math.sin(angleAR);
System.out.println("Base s = " + baseS);
// Calculates the perimeter
double perimeter = baseS * numSides;
System.out.println("Polygon perimeter = " + perimeter);
// Calculates approximate value of Pi
double piEst = perimeter/2.0;
System.out.println("Estimate of PI = " + piEst);
}
}