LintCode_Java旅程 矩阵面积


礼悟:
           公恒学思合行悟,尊师重道存感恩。叶见寻根三返一,江河湖海同一体。
           虚怀若谷良心主,愿行无悔给最苦。读书锻炼养身心,诚劝且行且珍惜。


 

LintCode是一个优秀的平台,值得推荐。平台链接是:http://www.lintcode.com/zh-cn/

 

 

题目叙述:

实现一个矩阵类Rectangle,包含如下的一些成员变量与函数:

  1. 两个共有的成员变量 widthheight 分别代表宽度和高度。
  2. 一个构造函数,接受2个参数 width 和 height 来设定矩阵的宽度和高度。
  3. 一个成员函数 getArea,返回这个矩阵的面积。

 注:给最苦 仅从全部的题目叙述中提取出了重要的部分,想要查看全部的题目叙述,请登录LintCode。

 

 

参考代码:

/**
 * LintCode 入门 矩阵面积
 *
 * @author jizuiku
 * @version V17.09.29
 */
public class Rectangle {
    /*
     * Define two public attributes width and height of type int.
     */
    // write your code here
    private int width;
    private int height;

    /*
     * Define a constructor which expects two parameters width and height here.
     */
    // write your code here
    Rectangle(int width , int height){
        this.width = width;
        this.height = height;
    }
    
    /*
     * Define a public method `getArea` which can calculate the area of the
     * rectangle and return.
     */
    // write your code here
    public int getArea(){
        return this.width * this.height;
    }
}

 

 

测试结果:

 

 


LintCode,提升技术的优秀平台,推荐。
Java优秀,值得学习。 

智能推荐

注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



猜您在找
【LintCode-454】矩阵面积(Java实现) LintCode之矩阵面积 (lintcode)第454题 矩阵面积 【LintCode 入门】454. 矩阵面积 Java基础 矩阵面积
智能推荐
 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告