2个回答
展开全部
public class Rectangle{
private int left,top,right,bottom;
public Rectangle(int left,int top,int right,int bottom){
this.left=left;
this.top=top;
this.right=right;
this.bottom=bottom;
}
public int getWidth(){
return Math.abs(right-left);
}
public int getHeight(){
return Math.abs(top-bottom);
}
public int getPerimeter(){
return (getWidth()+getHeight())*2;
}
public int getArea(){
return getWidth()*getHeight();
}
public static void main(String []args){
Rectangle rect=new Rectangle(0,0,50,60);
System.out.println("Perimeter:"+rect.getPerimeter());
System.out.println("Area:"+rect.getArea());
}
}
private int left,top,right,bottom;
public Rectangle(int left,int top,int right,int bottom){
this.left=left;
this.top=top;
this.right=right;
this.bottom=bottom;
}
public int getWidth(){
return Math.abs(right-left);
}
public int getHeight(){
return Math.abs(top-bottom);
}
public int getPerimeter(){
return (getWidth()+getHeight())*2;
}
public int getArea(){
return getWidth()*getHeight();
}
public static void main(String []args){
Rectangle rect=new Rectangle(0,0,50,60);
System.out.println("Perimeter:"+rect.getPerimeter());
System.out.println("Area:"+rect.getArea());
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询