zoukankan      html  css  js  c++  java
  • 第七周作业

    1 定义三个方法:getArea()求面积、getPer()求周长,showAll()分别在控制台输出长、宽、面积、周长。
    2 有2个属性:长length、宽width
    3 创

    public class Rectangle {
        int length;
        int width;
    
        Rectangle(int width, int length) {
            this.width = width;
            this.length = length;
        }
    
        void getArea() {
            System.err.println("面积:"+width*length);
        }
    
        void getPer() {
            System.out.println("周长:"+(width+length)*2);
        }
    
        void showAll() {
            System.out.println("长:"+length+"  宽:"+width);
        }
         
    }

    3 创建一个Rectangle对象,并输出相关信息

    public static void main(String[] args) {
                Rectangle a = new Rectangle(2, 5);
                a.getArea();
                a.getPer();
                a.showAll();
                
            }
        }

    建一个Rectangle对象,并输出相关信息

  • 相关阅读:
    模块 hashlib模块
    设计模式
    类中双下方法
    工作小结 常见定制类
    python collections模块
    启动脚本
    anaconda镜像
    理解python的可变参数
    使用spark
    python 异常处理
  • 原文地址:https://www.cnblogs.com/zhangjiatong/p/12738582.html
Copyright © 2011-2022 走看看