yanrun
public class Rectangle {
private double length;
private double width;
public Rectangle(double length, double width) {
this.length = length;
this.width = width;
}
public double getArea() {
return this.length * this.width;
}
public double getPerimeter() {
return (this.length + this.width) * 2;
}
public static void main(String[] args) {
Rectangle r = new Rectangle(4, 3);
System.out.println("面积为:" + r.getArea());
System.out.println("周长为:" + r.getPerimeter());
}
}