public class Area{
private int length;
private int width;
public Area(int length,int width){
this.length=length;
this.width=width;
}
public int getArea(){//计算面积
return length*width;
}
public static void main(String[] args){
Area a=new Area(20,10);
int area1=a.getArea();//计算第一个长方形面积
System.out.println("第一个长方形的面积为:"+area1);
Area b=new Area(6,3);//计算第二个长方形面积
int area2=b.getArea();
System.out.println("第二个长方形的面积为:"+area2);
}
}

 

相关文章:

  • 2021-08-27
  • 2021-05-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-05-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案