怎么用java计算梯形面积
来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/11/19 00:02:54
怎么用java计算梯形面积
Suppose that bases of a trapezoid are 8.9 and 12.1,and that the height is 16.Use Dr.Java's interactions pane to declare variables for the bases,height,and area,assign values,and compute the area.
What code did you type to declare the four variables you needed?
What code did you type to assign values to the bases and the height?
What code did you type to compute the area?
What is the area of this trapezoid?
Suppose that bases of a trapezoid are 8.9 and 12.1,and that the height is 16.Use Dr.Java's interactions pane to declare variables for the bases,height,and area,assign values,and compute the area.
What code did you type to declare the four variables you needed?
What code did you type to assign values to the bases and the height?
What code did you type to compute the area?
What is the area of this trapezoid?
public class Test{
//梯形面积的方法
//a为梯形上底,b为梯形下底,h为梯形高,area为面积
public double area(double a,double b,double h){
double area;
//梯形面积公式:(上底+下底)*高/2
area=(a+b)*h/2;
return area;
}
//使用mian()方法实现
public static void main(String [] args){
Test t=new Test();
System.out.print("梯形面积为"+t.area(8.9,12.1,16));
}
}
//梯形面积的方法
//a为梯形上底,b为梯形下底,h为梯形高,area为面积
public double area(double a,double b,double h){
double area;
//梯形面积公式:(上底+下底)*高/2
area=(a+b)*h/2;
return area;
}
//使用mian()方法实现
public static void main(String [] args){
Test t=new Test();
System.out.print("梯形面积为"+t.area(8.9,12.1,16));
}
}