java矩形类

2020-12-13 13:54

阅读:474

标签:image   oid   图片   bsp   color   rectangle   rgs   style   div   

public 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();
    }
}

技术图片

 

java矩形类

标签:image   oid   图片   bsp   color   rectangle   rgs   style   div   

原文地址:https://www.cnblogs.com/-vampire-/p/11544526.html


评论


亲,登录后才可以留言!