您的位置:首页 > 其它

用Rectangle输出一个矩形的周长和面积

2017-11-16 11:12 495 查看
/*

 * 用Rectangle输出一个矩形的周长和面积

 */


public class Rectangle {
private int width;
private int height;
public static void main(String[] args) {
//声明变量
Rectangle rec = new Rectangle(36,21);
System.out.println("这个矩形的周长是:"+rec.getPerimeter());
System.out.println("这个矩形的面积是:"+rec.getArea());
}
public int getPerimeter(){
return this.width *2 + this.height *2;
}
//获得矩形的周长
public int getArea(){
return this.width * this.height;
}
//获得矩形的面积
public Rectangle(int width,int height) {
super();
this.width = width;
this.height = height;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐