Area of circle through command line argument
class Circle {
double radius;
public Circle () {
radius = 0;
}
public Circle(double r) {
radius = r;
}
public void setLength(double r) {
radius = r;
}
public double getLength () {
return radius;
}
public double Area() {
return (radius * radius * 3.1459);
}
public double Perimeter() {
return (2*3.1459*radius);
}
}
public class CircleDemo {
public static void main(String[] args){
int n = args.length;
if(n != 1) {
System.out.println("expected one arguments");
return;
}
double pr = Double.parseDouble(args[0]);
Circle circ = new Circle(pr);
double area = circ.Area();
pr = circ.getLength();
double temp = 3.1450*pr*pr;
System.out.println(area);
System.out.println(temp);
}
}
No comments:
Post a Comment