Calculate circumference of Circle
Source Code
package
inherit;
public
class
CircumCircle {
final
double
PI
= 3.1415;
double
radius;
CircumCircle(double
r){
this.radius=r;
}
void
displayCircum(){
System.out.println("Radius="+this.radius);
System.out.println("Circumference="+
2*PI*this.radius);
}
}
package
inherit;
public
class
Circle {
public
static
void
main(String[] args){
CircumCircle
c1=new
CircumCircle(2);
CircumCircle
c2=new
CircumCircle(2.5);
c1.displayCircum();
c2.displayCircum();
}
}
Output:
No comments:
Post a Comment