

 Thread Tools  Search this Thread 
#1
 
 
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
 
 
Re: How to calculate area of Circle in Java? Code: import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class CircleArea { public static void main(String[] args) { int r = 0; System.out.println(" enter radius "); try { BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in)); r = Integer.parseInt(br1.readLine()); } 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
 
 
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
 
 
Re: How to calculate area of Circle in Java? Code: import java.io.*; class AreaOfCircle { public static void main(String[] args){ int radius=0; try{ BufferedReader br2 = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter Radius of Circle : "); radius = Integer.parseInt(br2.readLine()); double area1 = java.lang.Math.PI*radius*radius; System.out.println("Area of Circle : "+area1); } catch(Exception e){ System.out.println("Error : "+e); } } } 
#5
 
 
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: circle, java, java language, java programming, radius 
Thread Tools  Search this Thread 

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  08122011 11:47 PM 
Program to calculate days difference between two dates in java.  KADRI  Software Development  5  16032011 06:22 PM 
micromax Q3 Vs Fly Circle  Truster  Portable Devices  10  27032010 08:22 AM 
How to Calculate Process Time in Java?  Bhardwaj  Software Development  3  08122009 12:25 PM 
How to draw a circle using TI 89  Bilal  Windows Software  3  20062009 11:55 AM 