前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >LintCode-454.矩阵面积

LintCode-454.矩阵面积

作者头像
悠扬前奏
发布2019-05-28 14:42:35
4250
发布2019-05-28 14:42:35
举报

题目

描述

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

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

样例

代码语言:javascript
复制
Rectangle rec = new Rectangle(3, 4);
rec.getArea(); // should get 12

解答

太简单了。不多说

代码:

代码语言:javascript
复制
public class Rectangle {
    /*
     * Define two public attributes width and height of type int.
     */
    // write your code here
    public int width;
    public int height;
    /*
     * Define a constructor which expects two parameters width and height here.
     */
    // write your code here
    public 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);
    }
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017.06.19 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 题目
    • 描述
      • 样例
      • 解答
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档