创建一个类 ,分别计算矩形的面积和周长

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;
}
创建一个类 ,分别计算矩形的面积和周长_第1张图片
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);
}
}

你可能感兴趣的:(创建一个类 ,分别计算矩形的面积和周长)