创建一个lader类
public class lader {
float above;
float bottom;
float height;
float area;
float computerArea() { //定义方法computerArea
area =(above+bottom)*height/2.0f;
return area;//返回梯形面积
}
void setHeight(float h) {
height=h;//设置高
}
}
在main类里调用lader类和里面的方法
public class main {
public static void main(String[] args) {
lader sca =new lader();
sca.setHeight(10);
sca.above=10;
sca.bottom=5;
System.out.println(sca.computerArea());
}
}
输出结果: