求大神帮忙解决
java编写一个三角形类,成员变量包括底和高,设置方法,返回三角形面积的方法
2条回答 默认 最新
- CSDN专家-sinJack 2021-10-28 05:36关注
三角形是正三角形?
public class Triangle { private double height; private double bottom; public Triangle(double height, double bottom) { this.height = height; this.bottom = bottom; } public double getArea(){ return 0.5*height*bottom; } public static void main(String[] args) { Triangle t=new Triangle(3,4); System.out.println("三角形面积为:"+t.getArea()); } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用