给你个示例参考:
import java。util。ArrayList;
import java。util。List;
import java。util。Scanner;
public class CuboidDemo {
public static void main(String[] args) {
intln("请输入3个长方体的长、宽、高: ");
int i = 1;
int length = 0 ;
int width = 0;
int height = 0 ;
List list = new ArrayList();
Scanner input = new Scanner( );
try{
while(true){
intln("第" + i + "个长方体: ");
int("长= ");
length = xtInt();
int("宽= ");
width = xtInt();
int("高= ");
height = xtInt();
intln();
Cuboid cuboid = new Cuboid(length,width,height);
d(cuboid);
i++;
if(i>3){
break;
}
}
}catch (Exception e) {
intln("输入有错!");
}
for(int n = 0; n < ze() ; n++){
intln("第" + (n+1) + "个长方体 参数: " + t(n));
intln("第" + (n+1) + "个长方体 体积: " + t(n)。
getBulk());
}
}
}
class Cuboid {
private int length = 0 ;
private int width = 0;
private int height = 0 ;
public Cuboid(){
}
public Cuboid(int length,int width,int height){
this。
length = length;
this。width = width;
this。
height = height;
}
public int getBulk(){
return length*width*height;
}
public String toString() {
return "[length=" + length + ", width=" + width + ", height="
+ height + "]";
}
}
。
全部