2248: 计算矩形面积
金币值:2
定数:6
时间限制:1.000 s
内存限制:128 M
正确:1
提交:1
正确率:100.00% 命题人:
题目描述
写一个名为Rectangle的类表示矩形。其成员变量有宽width、高length、颜色color,width和length是double类型,color是String类型。假定所有矩形的颜色相同,用一个类变量表示颜色。要求提供构造方法和计算矩形面积的computeArea()方法。
import java.util.Scanner; public class Main { public static void main(String[] args) { double width, length; String color; Scanner in = new Scanner(System.in); color = in.nextLine(); width = in.nextDouble(); length = in.nextDouble(); Rectangle.color = color; Rectangle r = new Rectangle(width, length); System.out.println("computeArea:" + r.computeArea() + ",color:" + Rectangle.color); } } /*以下为你的代码*/
输入格式
第1行:颜色
第2行:宽
第3行:长
第2行:宽
第3行:长
输出格式
见样例
输入样例 复制
red
1
2
输出样例 复制
computeArea:2.0,color:red