2253: 立方体体积
金币值:2
定数:6
时间限制:1.000 s
内存限制:128 M
解决:1
提交:2
正确率:50.00% 命题人:
题目描述
编程创建一个Box 类,在其中定义三个变量表示一个立方体的长、宽和高,定义一个构造方法对这三个变量进行初始化,然后定义一个方法求立方体的体积。创建一个对象,求给定尺寸的立方体的体积。
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
float length, width, height;
Scanner in = new Scanner(System.in);
length = in.nextFloat();
width = in.nextFloat();
height = in.nextFloat();
Box b = new Box(length, width, height);
System.out.println(b.getVolume());
length = in.nextFloat();
width = in.nextFloat();
height = in.nextFloat();
b.setHeight(height);
b.setLength(length);
b.setWidth(width);
System.out.println(b.getVolume());
}
}
/* 以下为你的代码 */ 输入
共6行:分别为构造时和设置时的长宽高
输出
见样例
样例输入 复制
10
5
8
10
10
10
样例输出 复制
400.0
1000.0