
展开全部
public class Rec {
private int width;
private int height;
public Rec(int width,int height){
this.width=width;
this.height=height;
}
public int area(){
return width*height;
}
public int perimeter(){
return 2*(width+height);
}
}
public class Test {
public static void main(String[] args){
Rec rec=new Rec(3,5);
System.out.println("area="+rec.area());
System.out.println("perimeter="+rec.perimeter());
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询