public class student {
int length;
int width;
int height;
public student (int length, int width, int height) {
this.length = length;
this.width = width;
this.height= height;
}
public String showInfo() {
return "长:" + length + ";宽:" + width + ";高:" + height;
}
public int getV() {
return length * width * height;
}
public int getA() {
int area = (length * width + length * height + width * height) * 2;
return area;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
student stu = new student(10,20,30);
System.out.println(stu.showInfo());
System.out.println("体积:" + stu.getV());
System.out.println("表面积:" + stu.getA());
}
}
代码已经是最简了 没有办法优化 也没有优化的必要
public class student {
int length, width, height;
public student (int length, int width, int height) {
this.length = length;
this.width = width;
this.height= height;
}
public String showInfo() {
return "长:" + length + " 宽:" + width + " 高:" + height;
}
public int getV() {
return length * width * height;
}
public int getA() {
return (length * width + length * height + width * height) * 2;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
student stu = new student(10,20,30);
System.out.println(stu.showInfo() + "\n" + "体积:" + stu.getV() + "\n" + "表面积:" + stu.getA());
}
}
是要优化一下
那能不能改的长一点,就是看上去长的