声明一个矩形类Rectangle,其中有多个构造方法。用不同的构造方法创建对象,并输出矩形的周长和面积。
1个回答
展开全部
Rectangle r[] = new Rectangle[6];
r[0] = new Rectangle();
r[1] = new Rectangle(new Dimension(10,10));
r[2] = new Rectangle(10,10);
r[3] = new Rectangle(10,10, 100, 2);
r[4] = new Rectangle(new Point(4,5));
r[5] = new Rectangle(new Point(4,5), new Dimension(10,10));
r[6] = new Rectangle(r[4]);
for (int i=0;i<r.length;i++)
System.out.println("Area["+i+"]=" + r[i].height * r[i].width + "\n" + "Length["+i+"]=" + 2 * ( r[i].height + r[i].width ));
r[0] = new Rectangle();
r[1] = new Rectangle(new Dimension(10,10));
r[2] = new Rectangle(10,10);
r[3] = new Rectangle(10,10, 100, 2);
r[4] = new Rectangle(new Point(4,5));
r[5] = new Rectangle(new Point(4,5), new Dimension(10,10));
r[6] = new Rectangle(r[4]);
for (int i=0;i<r.length;i++)
System.out.println("Area["+i+"]=" + r[i].height * r[i].width + "\n" + "Length["+i+"]=" + 2 * ( r[i].height + r[i].width ));
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询