1 2 3 0 2 3 -1 2 3 3 4 5
22.00 6.00 11.25 2.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 94.00 60.00 49.04 20.00
四棱锥体公式:V=1/3Sh,S——底面积 h——高
很基础的题,就是求四棱锥的表面积的公式麻烦点
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
double l=sc.nextDouble();
double h=sc.nextDouble();
double z=sc.nextDouble();
Rect rect=new Cubic(l, h, z);
rect.area(l, h, z);
rect.volume(l,h,z);
rect=new Pyramid(l, h, z);
rect.area(l, h, z);
rect.volume(l, h, z);
}
sc.close();
}
}
class Rect {
double l, h, z;
public Rect(double l, double h, double z) {
if(l<=0||h<=0||z<=0)
{
l=0;
h=0;
z=0;
}
this.l = l;
this.h = h;
this.z = z;
}
public void volume(double l, double h, double z) {
}
public void length(double l, double h) {
System.out.printf("%.2f ",2 * (this.l + this.h));
}
public void area(double l, double h, double z) {
System.out.printf("%.2f ",this.l * this.h);
}
}
class Cubic extends Rect {
public Cubic(double l, double h, double z) {
super(l, h, z);
}
public void area(double l, double h, double z) {
System.out.printf("%.2f ",2 * (this.h * this.l + this.h * this.z + this.z * this.l));
}
public void volume(double l, double h, double z) {
System.out.printf("%.2f ",this.l * this.h * this.z);
}
}
class Pyramid extends Rect{
public Pyramid(double l, double h, double z) {
super(l, h, z);
}
public void area(double l, double h, double z) {
System.out.printf("%.2f ",Math.sqrt(this.h*this.h/4+this.z*this.z)*this.l+Math.sqrt(this.l*this.l/4+this.z*this.z)*this.h+this.l*this.h);
}
public void volume(double l, double h, double z) {
System.out.printf("%.2f\n",this.l *this. h * this.z/3);
}
}