QuestionAsk Questions?

Posted in : Java Beginners

Need simple Java Method example that returns area of circle

View Answers

February 23, 2008 at 3:50 PM

Java Example Code

With the help of given Java code you can return the area of a circle and give the radius as a parameter.

import java.io.*;

public class AreaAndParameter

{

public static void main(String[] args)

{

double r=0;

try{

BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in));

System.out.print("Enter Radius of Circle : ");

r = Integer.parseInt(br1.readLine());

AreaAndParameter a = new AreaAndParameter();

double area = a.areaOfCircle(r);

System.out.println("Area of Circle : "+area);

double perimeter = a.perimeterOfCircle(r);

System.out.println("Perimeter of Circle : "+perimeter);

}

catch(Exception e){

System.out.println("Error : "+e);

}

}

public double areaOfCircle(double r){

double area = Math.PI*r*r;

return area;

}

public double perimeterOfCircle(double r){

double perimeter = 2*Math.PI*r;

return perimeter; }}

Related Tutorials/Questions & Answers:

Advertisements