Area of Circle Java

Hey guys!! Welcome to flower brackets. Today we are going to learn area of circle java.

How do you find the area of a circle in Java?

Decades ago we have seen and learnt area of circle in our school in geometry class.

Also Read – Area of Rectangle Program in Java

I still remember the way how our geometry teacher explained the concept of area of a circle using compass and measuring the radius using ruler.

Good’ol days… Now we will see java program to find area of circle

// Area of circle is, area = pi * r * r where r is the radius of a circle

import java.io.IOException;

public class AreaOfCircle
{
public static void main(String[] args)
{
System.out.println("Enter the radius of a Circle: ");
try
{
}
// To check whether invalid value was entered
catch(NumberFormatException nfe)
{
System.exit(0);
}
catch(IOException ioe)
{
System.out.println("IO Error: " + ioe);
System.exit(0);
}
System.out.println("Area of a circle is " + circleArea);
}
}

Output:
Enter the radius of a Circle: 10
Area of a circle is 314.1592653589793

Java program to calculate circumference of circle in java

Let’s see java program to calculate circumference of circle.

import java.util.Scanner;

public class CircleCircumference
{
public static void main(String[] args)
{
// Here we are declaring Scanner class which could read from console
Scanner sc = new Scanner(System.in);
double circumference = 0.0;
// Formula for calculating circumference of circle
// circumference = 2 * 22 / 7 * radius
circumference = 2 * Math.PI * radius;
System.out.println("Circumference of circle is : " + circumference);
}
}

Output:

Circumference of circle is : 31.41592653589793

Java program to calculate area of circle using methods

Here we are going to see java program to calculate area of circle using method.

import java.util.Scanner;

public class AreaOfCircleDemo
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("The area of circle is : " + area);
sc.close();
}

static double calculateArea(double r)
{
return (22 * r * r) / 7;
}
}

Output: