2253: 立方体体积
金币值:2
定数:6
时间限制:1.000 s
内存限制:128 M
正确:0
提交:0
正确率:0.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