Join
Blogs
Questions
Videos
Tags
Members
Search
 
 
Create your own blog, earn points and get popular!

Write a program to calculate Circle area

  1. /*
  2.  * Write a program to calculate Circle area. Program should have class called
  3.  * Circle with radius as member variable and getArea member method.
  4.  * getArea method should print area of the Circle object.
  5.  */
  6.  
  7. class Circle{
  8.  
  9.  int r;
  10.  
  11.  void setData(int x){
  12.   r = x;
  13.  }
  14.  
  15.  void getArea(){
  16.  
  17.   //area of circle is  = pi * r * r
  18.   System.out.println("Area of Circle: " + (3.14 * r * r));
  19.  }
  20. }
  21.  
  22. public class CircleArea
  23. {
  24.  public static void main(String args[]){
  25.  
  26.   Circle c1 = new Circle();
  27.   c1.setData(10);
  28.   c1.getArea();
  29.  
  30.   Circle c2 = new Circle();
  31.   c2.setData(4);
  32.   c2.getArea();
  33.  }
  34. }
Your rating: None Average: 1.7 (3 votes)
Share this

Post new comment

3 + 0 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.