今天做了圆类的习题
package Circle; import java.io.IOException;import java.util.Scanner; public class Circle {
public static void main(String[] args)throws IOException{
Circle c1 = new Circle();
Scanner input = new Scanner(System.in);
double r = input.nextDouble();
c1.setRadius(r);
System.out.println(c1.circumference());
System.out.println(c1.area());
Circle c2 = new Circle(c1);
System.out.println(fCircle_L(c2));
System.out.println(fCircle_S(c2));
}
static double PI = 3.1415;
static double radius;
Scanner input = new Scanner(System.in);
public Circle(){
radius=0;
System.out.println("Constructor run");
}
public Circle(double r){
radius = r;
System.out.println("Constructor run");
}
public Circle(Circle cir){
radius = cir.radius;
System.out.println("CopyConstructor run");
}
void setRadius(double r){radius = r;}
double getDadius(){return radius;}
double circumference(){return 2*PI*radius;}
double area(){return PI*radius*radius;}
static double fCircle_L(Circle r){return 2*PI*r.radius;}
static double fCircle_S(Circle r){return PI*r.radius*r.radius;}
}