# Java program to calculate area of circle using method

Let’s learn java program to calculate area of circle using method.

## Java program to calculate area of circle using method

To find area of a circle using method in java, first we have to write calculateArea() method which accepts radius as parameter to calculate area of circle in java.

Then in the next step, in main() method we have to call calculateArea() method.

Also read – java program to calculate area of rectangle

Here’s the java program to calculate area of circle using method.

```import java.util.Scanner;
public class AreaOfCircleMethod
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
// area of circle in java
System.out.println("Area of circle : " + area);
sc.close();
}
static double calculateArea(double r)
{
return (22 * r * r) / 7;
}
}

```

Output:

Area of circle : 78.57142857142857

Similarly we can calculate area of circle without using method. Here’s the java program – click here.

Java program to calculate area and circumference of circle using methods

Here’s the java program to calculate area and circumference of circle using methods.

```import java.util.Scanner;
public class CalculateAreaOfCircleMethod
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Area of circle: " + area);
System.out.println("Circumference of circle: " + circumference);
sc.close();
}
static double calculateArea(double r)
{
return (22 * r * r) / 7;
}
{
return Math.PI * 2 * rad;
}
}

```

Output:

Area of circle: 314.2857142857143
Circumference of circle: 62.83185307179586

### program to find area of circle and rectangle

Here’s the java program to find area of circle and rectangle.

```public class FindAreaOfCircleRectangle
{
public static void main(String[] args)
{
int length = 30;
int breath = 10;
System.out.println("Area of rectange is: " + length * breath);
System.out.println("Area of circle is: " + (22 * radius * radius) / 7);
}
}

```

Output:

Area of rectange is: 300
Area of circle is: 78.57142857142857

Java program to calculate area of circle rectangle and triangle using switch statement

Here’s the java program to calculate area of circle rectangle and triangle using switch statement.

```import java.util.Scanner;
public class FindAreaUsingSwitchStatement
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("1.Area of circle");
System.out.println("2.Area of triangle");
System.out.println("3.Area of rectangle");
System.out.println("Please enter any of the above option: ");
int num = sc.nextInt();
switch(num)
{
System.out.println("Area of circle is: " + areaCircle);
break;
case 2: System.out.println("Please enter base and height of triangle: ");
double base = sc.nextFloat();
double height = sc.nextFloat();
double areaTriangle = (base* height) / 2;
System.out.println("Area of triangle is: " + areaTriangle);
break;
int length = sc.nextInt();
int areaRectangle = length * breadth;
System.out.println("Area of ractangle is: " + areaRectangle);
break;
default:System.exit(0);
}
sc.close();
}
}

```

Output:

1.Area of circle
2.Area of triangle
3.Area of rectangle
Please enter any of the above option: 1
Area of circle is: 78.57142857142857

1.Area of circle
2.Area of triangle
3.Area of rectangle
Please enter any of the above option: 2
Please enter base and height of triangle:
20
100
Area of triangle is: 1000.0

1.Area of circle
2.Area of triangle
3.Area of rectangle
Please enter any of the above option: 3
50
20
Area of ractangle is: 1000

Java program to find area of circle and rectangle using interface

```interface FindArea
{
double pi = 3.14159265359;
double calculate(double a, double b);
}
class Rectangle implements FindArea
{
public double calculate(double a, double b)
{
return(a * b);
}
}
class Circle implements FindArea
{
public double calculate(double a, double b)
{
return(pi * a * a);
}
}
public class FindAreaUsingInterface
{
public static void main(String[] args)
{
Rectangle rect = new Rectangle();
Circle cir = new Circle();
FindArea area;
area = rect;
System.out.println("Area of rectangle is: " + area.calculate(50, 30));
area = cir;
System.out.println("Area of circle is: " + area.calculate(10, 10));
}
}

```

Output:

Area of rectangle is: 1500.0
Area of circle is: 314.15926535899996