LintCode练习,求矩阵面积

454. 矩阵面积

实现一个矩阵类Rectangle,包含如下的一些成员变量与函数:
  1. 两个共有的成员变量 width 和 height 分别代表宽度和高度。
  2. 一个构造函数,接受2个参数 width 和 height 来设定矩阵的宽度和高度。
  3. 一个成员函数 getArea,返回这个矩阵的面积。
public class Rectangle {
    
    
    /*
     * Define two public attributes width and height of type int.
     */
    int height=0,weight=0;

    public Rectangle(int height,int weight){
    
    
		this.height=height;
		this.weight=weight;
	}
	
	public int getArea(){
    
    
		return height * weight;
	}
}

若加上主函数

public static void main(String args[]){
    
    
		Solution so = new Solution(3, 4);
		System.out.println(so.getArea());
	}

猜你喜欢

转载自blog.csdn.net/A_Tu_daddy/article/details/103539659