问题 问答题

按以下要求编写程序
(1) 创建一个Rectangle类,添加width和height两个成员变量
(2) 在Rectangle中添加两种方法分别计算矩形的周长和面积
(3) 编程利用Rectangle输出一个矩形的周长和面积

答案

参考答案:

public class Rectangle {
  float width, height;
  public Rectangle(float width, float height) {
    this.width = width;
    this.height = height;
  }
  public float getLength______{
    return (this.width + this.height) * B;
  }
  public float getArea______{
    return this.width * this.height;
  }
  public static void main(String [] args) {
    Rectangle rect = new Rectangle(A0, B0);
    System.out.println("周长是:" + rect.getLength______);
    System.out.println("面积是:" + rect.getArea______);
  }
}

单项选择题 B1型题
单项选择题