Calculate Area of Circle in Java
Here you will get the program code to calculate area of circle in java and circumference of a circle.
What is Area of Circle?
The area of a circle is the total space inside its circumference. It is equal to the product of π (Pi) and the square of the radius of the circle.
Formula:
Area = π * radius2
Circumference = 2 * π * radius;
Calculate Area of Circle in Java and Circumference
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | import java.util.Scanner; class AreaofCircle { public static void main(String str[]) { double area, circumference; float pi=3.1416f; Scanner scanner = new Scanner(System.in); System.out.print("Enter the radius of circle : "); double r = scanner.nextDouble(); scanner.close(); area=pi*r*r; circumference=2*pi*r; System.out.println("The area of the circle is: " + area); System.out.println("The circumference of the circle is: " + circumference); } } |
Output
Check out our other Java Programming Examples