您的位置:首页 > 编程语言 > Java开发

Java计算矩形的面积和周长

2017-09-06 22:27 1746 查看
代码如下

package one;

public class TestRectangle {
public static void main(String[] args){
Rectangle zheng = new Rectangle();
zheng.height=20;
zheng.width=10;
int area = zheng.calArea();
System.out.println("周长为"+area);
int aree =zheng.calPefimeter();
System.out.println("面积为"+aree);
}
}

class Rectangle{
int height;
int width;
public int calArea(){
return 2*height + 2*width;
}
public int calPefimeter(){
return height * width;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java
相关文章推荐