怎么用java计算梯形面积 急!!!!!
Supposethatbasesofatrapezoidare8.9and12.1,andthattheheightis16.UseDr.Java'sinteractio...
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? 展开
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));
}
}
展开全部
首先你要定义三个变量:上底,下底.高/定义成folat/然后你可以用一些算法计算你所需要的面积.
folat a,b,h ,area;
public void Area(folat a,folat b){
this.a=a;this.b=b;
area=((a+b)*h)/2;
}然后再调用 这个方法!我想就会吧!(我也是新手)
folat a,b,h ,area;
public void Area(folat a,folat b){
this.a=a;this.b=b;
area=((a+b)*h)/2;
}然后再调用 这个方法!我想就会吧!(我也是新手)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你首先要学好的是数学,用java写着个程序,无非是把求梯形的面积公式用java的运算符表达出来,上底 下底 高,都是做为变量,输出结果作为变量。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询