1418: 矩形类

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:491 解决:340

题目描述

请你定义应该矩形类Rectangle,包含长height和宽width。并请你给出求矩形面积的方法(函数)area(),和适当的get方法和set方法(函数)。请你求矩形的面积。


public class Main {
  public static void main(String[] args) { 
    Scanner sin = new Scanner(System.in); 
    while(sin.hasNext()){ 
      int height = sin.nextInt(); 
      int width = sin.nextInt(); 
      Rectangle rec = new Rectangle();
      rec.setWidth(width);
      rec.setHeight(height); 
      System.out.println(String.format("%.2f",rec.area()));
    } 
  } 
}



输入

输入有多组。每组2个正整数,分别表示矩形的长和宽。

输出

输出矩形的面积。结果保留2位小数。

样例输入 复制

1 2
3 4

样例输出 复制

2.00
12.00

来源/分类