Let's learn java programming language with easy steps. This Java tutorial provides you complete knowledge about java technology.

Saturday 2 December 2017

Java Program To Calculate Area and Circumference of Circle

Java Program To Calculate Area and Circumference or Perimeter of Circle

Java Program To Calculate Area and Circumference of Circle

In the last post, We saw some examples of how to calculate an area of the triangle in java but here we are going to see java program to calculate area and circumference of circle by the help of different - different java programs.

Let's see java program for area of circle with step-by-step.

We will use formula to calculate the area and perimeter or circumference of circle. The formula is given below.

1) Calculate Area of Circle Formula

PI*radius*radius 

2) Calculate Circumference of Circle Formula

2*pi*radius 


(1) Area of Circle in Java Program 1

This is simple java program to find area of circle where we will take radius value from the user and then calculate area of circle.

import java.util.Scanner;
class AreaOfCircle
{
public static void main(String args[])
{
//creating Scanner 
Scanner sc = new Scanner(System.in);

System.out.println("Enter radius of circle");
double radius = sc.nextDouble();

double area = Math.PI*radius*radius;
System.out.println("Area of Circle is : "+area);
}
}

Output: Enter radius of circle
             5
            Area of Circle is : 78.53981633974483


(2) Area of Circle in Java Program 2

This is another java program to calculate area of circle using constructor where we create constructor for calculating the circle area.

import java.util.Scanner;
class AreaOfCircle2
{
double area;

AreaOfCircle2(double radius)
{
area = Math.PI*radius*radius;
System.out.println("Area of Circle is : "+area);
}
}

class Test
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter radius of Circle");

double r = sc.nextDouble();
AreaOfCircle2 a = new AreaOfCircle2(r);
}
}

Output: Enter radius of Circle
             5
             Area of Circle is : 78.53981633974483

Let's take another simple java program to find area of circle.


(3) Area of Circle in Java Program 3

This another simple java program to calculate area of circle using method.

import java.util.*;
class AreaOfCircle3
{
//creating static method to find area of circle in java

static double area(double radius)
{
return Math.PI*radius*radius;
}

public static void main(String args[])
{
Scanner sc = new Scanner(System.in);

System.out.println("Enter radius of circle");
double r = sc.nextDouble();
double d = area(r);

System.out.println("Area of Circle is : "+d);
}
}

Output: Enter radius of circle
             5
             Area of Circle is : 78.53981633974483


(4) Calculate Circle Perimeter Using Java Example

In this example we will calculate the circle perimeter or circumference by using 2*pi*radius formula.

import java.util.Scanner;
class CircleCircumferenceExample
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);

System.out.println("Enter radius of Circle");
double radius = sc.nextDouble();
double circumference = Math.PI*2*radius;

System.out.println("Circumference of Circle : "+circumference);
}
}

Output: Enter radius of Circle
             5
            Circumference of Circle : 31.41592653589793

Read More:

How to Calculate Area of Square in Java.
How to Calculate Area and Perimeter of a Rectangle in Java.
Java Program to Check Leap Year on not.
Java Program for Binary Search.
Java Program for Linear Search.

Here we discussed that how to calculate area of circle through java program and how to find the perimeter of circle through java program with different - different examples. 

Share:

1 comment:

  1. I was more than happy to uncover this great site. I need to to thank you for your time due to this fantastic read!! I definitely enjoyed every bit of it and I have you bookmarked to see new information on your blog.
    Java Training in Bangalore

    ReplyDelete

Facebook Page Likes

Follow javatutorial95 on twitter

Popular Posts

Translate