java怎么编写求长方形表面积和体积的代码

2024-12-15 21:01:01
推荐回答(2个)
回答1:

//主要代码 System.out.print("长:") double num1=input.nextDouble(); //代码太多以后简写System...("宽:"); double num2=.... System....("高:")double num3=.... System...("表:"+(num1*num2+num1*num3+num2*num3)*2+" 体积:"+n1*n2*n3)//打字不容易求给分

回答2:

public class Rectangular {
private double height;
private double widht;
private double length;
public double getcapacity(){
return height*widht*length;
}
public double getArea(){
return (height*widht+widht*length+height*length)*2;

}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
public double getWidht() {
return widht;
}
public void setWidht(double widht) {
this.widht = widht;
}
public double getLength() {
return length;
}
public void setLength(double length) {
this.length = length;
}

}

public class RectangularAction {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Rectangular rec=new Rectangular();
rec.setHeight(1.1);
rec.setLength(3.4);
rec.setWidht(2.5);
System.out.println("体积"+rec.getcapacity()+"表面积"+rec.getArea());
}

}