User Name Remember Me? Password

# How to calculate area of Circle in Java?

## Software Development

#1
 Aandaleeb Member Join Date: May 2009 Posts: 1,187
How to calculate area of Circle in Java?

Hi,
I am second year computer engineer student. As per our syllabus we have java language. In our last exam in java paper one program is asked like How to calculate Area of Circle? I used various method but unable to write right program. That's why I decide to take help of you. If you know how to write this program then please give me.

#2
 Praetor Member Join Date: Apr 2008 Posts: 1,948
Re: How to calculate area of Circle in Java?

Code:
```import java.io.BufferedReader;

import java.io.IOException;

public class CircleArea
{

public static void main(String[] args)
{

int r = 0;

System.out.println(" enter radius ");
try

{

}

catch(NumberFormatException ne)

{

System.out.println("Invalid radius value" + ne);

System.exit(0);

}

catch(IOException ioe)

{

System.out.println("IO Error :" + ioe);

System.exit(0);

}
double a = Math.PI * r * r;

System.out.println("Area of  circle is " + a);

}
}```
#3
 Katty Member Join Date: May 2008 Posts: 2,008
Re: How to calculate area of Circle in Java?

Hey I am not writing any program for you rather I give you logic behind it. You have to use following formula to calculate area of circle.

The formula is as follows:

Area of circle=Pi *r*r

where r=radius of circle,pi=3.14

You have to take radius from the user and save it in "r".
#4
 kelfro Member Join Date: Apr 2008 Posts: 2,001
Re: How to calculate area of Circle in Java?

Code:
```import java.io.*;
class AreaOfCircle
{
public static void main(String[] args){
try{
System.out.println("Enter Radius of Circle  : ");
System.out.println("Area of Circle : "+area1);

}
catch(Exception e){
System.out.println("Error : "+e);
}
}
}```
#5
 Zecho Member Join Date: May 2008 Posts: 2,293
Re: How to calculate area of Circle in Java?

This is one of the simplest and easiest progran.

Code:
```class StaticCircle
{
public double r;
double  pi=3.14;
public void circle(double r)
{
this.r=r;

}
public double area()
{
double a1 = r*r;
double piV= a1*pi;
return piV;
}
public static void main(String[] args)
{
StaticCircle  sCircle  = new StaticCircle ();
sCircle.circle(10);
double t = sCircle.area();
System.out.println("The area is " + t);
}
}```

 Tags:

 Thread Tools Search this Thread Show Printable Version Email this Page Search this Thread: Advanced Search Similar Threads for: "How to calculate area of Circle in Java?" Thread Thread Starter Forum Replies Last Post How to calculate simple interest in java ? xanix Software Development 7 08-12-2011 11:47 PM Program to calculate days difference between two dates in java. KADRI Software Development 5 16-03-2011 06:22 PM micromax Q3 Vs Fly Circle Truster Portable Devices 10 27-03-2010 08:22 AM How to Calculate Process Time in Java? Bhardwaj Software Development 3 08-12-2009 12:25 PM How to draw a circle using TI 89 Bilal Windows Software 3 20-06-2009 11:55 AM

All times are GMT +5.5. The time now is 03:42 PM. 