Monday, July 27, 2009

Java Program to find the Area and Circumference of Circle

Hi friends, welcome back to Java Code Online. Today I will give you a simple Java Program to find the Area and Circumference of a Circle.

The Area and Circumference depends on the radius of the circle, so the code first asks the user for the radius of the circle, and then computes the area and circumference of the circle.
The code is given below:-

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


public class AreaCircumferenceCircle {
final static float pi = 22/7f;

public static void main(String[] args) throws NumberFormatException, IOException {
System.out.println("Enter the radius of the circle: ");
InputStreamReader io= new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(io);
float radius = Float.parseFloat(br.readLine());
System.out.println("Area of the Circle is: "+radius*radius*pi);
System.out.println("Circumference of the Circle is: "+2*radius*pi);
}
}

I hope the above code was helpful to you all. For more info on Java, keep checking Java Code Online.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.