先写一个方法
public class yuan {
double radius;
public double findArea(){
return Math.PI*radius*radius;
}
}
然后再计算
public class yuanText {
public static void main(String[] args) {
yuan c = new yuan();
yuanText yuanText = new yuanText();
yuanText.printAreas(c,5);
System.out.println("new \t\t"+c.radius );
}
public void printAreas(yuan c,int time){
System.out.println("Radious\t\tArea");
for (int i = 1; i <=time ; i++) {
c.radius=i;
System.out.println(c.radius+"\t\t"+c.findArea());
}
c.radius=time+1;
}
}