java求长方形周长和面积

求解答( ๑ŏ ﹏ ŏ๑ )好人一生平安

img

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

  }
}