码迷,mamicode.com
首页 > 编程语言 > 详细

java矩形类

时间:2019-09-18 19:40:27      阅读:165      评论:0      收藏:0      [点我收藏+]

标签: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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!