Description

This basic java example source code reads radius of a circle from console input and then calculate the area and perimeter.

Circle Calculate Area and Perimeter Source Code

package com.javatutorialhq.java.examples;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/*
 * This basic java example source code
 * reads radius of circle from console input
 * Java Program to calculate the area and perimeter of Circle
 */

public class CircleCalculation {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// Declare the reader from console
		BufferedReader br;
		// Get the console input for the rectangle dimension
		System.out.println("Enter the radius of the Circle");
		System.out.print("Radius:");
		br = new BufferedReader(new InputStreamReader(System.in));
		// assign to double variable the radius console input
		double radius = Double.parseDouble(br.readLine());
		// calculate the area of circle
		double area = Math.PI * Math.pow(radius, 2) ;
		// calculate the perimeter of circle
		double perimeter = 2 * Math.PI * radius;
		System.out.println("Area is "+ area);
		System.out.println("Perimeter is "+perimeter);

	}

}

Sample Output

Enter the radius of the Circle
Radius:3.1
Area is 30.190705400997917
Perimeter is 19.477874452256717

Suggested Reading List