JAVA实操:[2]求矩形的周长和面积
/**
* @(#)Rectangle.java
*定义矩形类,计算给定边长的两个矩形的周长和面积。
*
* @author
* @version 1.00 2011/10/14
*/
public class Rectangle {
private double width;
private double height;
public Rectangle(double w,double h)
{
width=w;
height=h;
}
public double getArea()
{
double s;
s=width*height;
return s;
}
public double getCir()
{
return 2*(width+height);
}
}
class Test1{
public static void main(String[] args){
Rectangle r1=new Rectangle(3.5,25.5);
System.out.println(r1.getArea());
System.out.println(r1.getCir());
}
}
赞 (0)