您的位置:首页 > 其它

计算矩形的面积和周长

2017-12-29 15:49 357 查看
//计算矩形的面积和周长

public class chuanglei { // 创建一个Rectangle类

double width, length;//
double area, zhou;

chuanglei(double x) {
width = x;
length = x;
}

chuanglei(double w, double len) { 
width = w;
length = len;
}

public double zhouRectangle()
{
zhou = (width + length) * 2;
return zhou;
}
public double areaRectangle() {
area = width * length;
return area;
}
public static void main(String[] args) { 
double c, s;
chuanglei Rectangle1 = new chuanglei(15, 23);
chuanglei Rectangle2 = new chuanglei(6);
c = Rectangle1.zhouRectangle();
s = Rectangle2.areaRectangle();
System.out.println("周长是:" + c);
System.out.println("面积是:" + s);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐