
//EBU4201(2021/22) lab3- question2- Rectangle.java
public class Rectangle {
private int length;
private int width;
public int acreage;
public Rectangle(int length,int width){
this.length = length;
this.width = width;
}
public int acreage(){
this.acreage = this.width*this.length;
return acreage;
}
public static void main(String[] args) {
Rectangle l1 = new Rectangle(8,6);
Rectangle l2 = new Rectangle(7,7);
System.out.println(l1.acreage());
System.out.println(l2.acreage());
}
}
本文详细介绍了如何使用Java创建Rectangle类,定义长度和宽度属性,计算并返回面积的方法。通过Rectangle类的实例化,展示了如何在main方法中创建两个矩形对象并打印其面积。
406

被折叠的 条评论
为什么被折叠?



