1.题目:
2.代码:
public class Xain{ //定义类名,要与文件.class名字一样private double yibian; //封装private double erbian;private double sanbian;public Xain(double yibian,double erbian,double sanbian){ //初始化变量this.yibian=yibian;this.erbian=erbian;this.sanbian=sanbian;}public double SJXZC(){ //定义类方法return yibian + erbian +sanbian;}public double SSS(){ //定义类方法double s = SJXZC() / 2; // 半周长double area = Math.sqrt(s * (s - yibian) * (s - erbian) * (s - sanbian));return area;}public static void main(String[] args){Xain SJX = new Xain(3,4,5); //调用类double area= SJX.SSS(); //调用类方法 对象.类方法System.out.println(area);double zc = SJX.SJXZC();System.out.println(zc);}}
3.收获:
a.海伦公式
b.当无法解决报错问题时,交给GPT
c.定义类方法要用括号