codescracker


java

Java Program to Calculate Area and Circumference of Circle



« Previous Program Next Program »


Calculate Area & Circumference of Circle

To calculate the area and circumference of any circle in Java Programming, you have to ask to the user to enter the radius of the circle and initialize the radius value in the variable say r and make two variable, one to store the area of the circle and the other to store the circumference of the circle, and place 3.14*r*r in area and 2*3.14*r in circumference, then display the result on the output screen.

Java Programming Code to Calculate Area Circumference of Circle

Following program ask to the user to enter the radius of a circle, to calculate and display the area and circumference of the circle:

Java Programming Example Code:
/* Java Program Example - Calculate Area Circumference of Circle */
		
import java.util.Scanner;

public class JavaProgram
{
    public static void main(String args[])
    {
        float r;
        double area, circum;
        Scanner scan = new Scanner(System.in);
		
        System.out.print("Enter Radius of Circle : ");
        r = scan.nextFloat();
		
        area = 3.14*r*r;
        circum = 2*3.14*r;
		
        System.out.print("Area of Circle = " +area);
		
        System.out.print("\nCircumference of Circle = " +circum);
    }
}

When the above Java Program is compile and executed, it will produce the following output:

Java Program calculate area circumference of circle

Same Program in Other Languages

You may also like to learn and practice the same program in other popular programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test