java矩形类
2020-12-13 13:54
标签:image oid 图片 bsp color rectangle rgs style div java矩形类 标签:image oid 图片 bsp color rectangle rgs style div 原文地址:https://www.cnblogs.com/-vampire-/p/11544526.htmlpublic class Rectangle {
private double width;
private double length;
public double area(){
double s;
s = width * length;
return s;
}
public double perimeter(){
double c;
c = (width + length) * 2;
return c;
}
public void set(double width, double length){
this.length = length;
this.width = width;
}
public void get(){
System.out.println("area = " + area());
System.out.println("perimeter = " + perimeter());
}
public static void main(String [] args){
double x,y;
Scanner in = new Scanner(System.in
);
Rectangle r = new Rectangle();
System.out.println("input wide and length here: ");
x = in.nextDouble();
y = in.nextDouble();
r.set(x,y);
r.get();
}
}
下一篇:C#泛型List的用法