package java3_26; public class java_3_26_4 public class Triangle { private double sideA; private double sideB; private double sideC; public Triangle(double sideA, double sideB, double sideC) { this.sideA = sideA; this.sideB = sideB; this.sideC = sideC; } public double getSideA() { return sideA; } public void setSideA(double sideA) { this.sideA = sideA; } public double getSideB() { return sideB; } public void setSideB(double sideB) { this.sideB = sideB; } public double getSideC() { return sideC; } public void setSideC(double sideC) { this.sideC = sideC; } public double getArea() { double p = (sideA + sideB + sideC) / 2.0; return Math.sqrt(p * (p - sideA) * (p - sideB) * (p - sideC)); } public double getPerimeter() { return sideA + sideB + sideC; } }错误: 在类 java3_26.java_3_26_4 中找不到 main 方法, 请将 main 方法定义为: public static void main(String[] args) 否则 JavaFX 应用程序类必须扩展javafx.application.Application
时间: 2023-05-31 18:02:51 浏览: 96
这段代码存在两个问题:
1. 类名与文件名不一致,应该将类名改为Triangle。
2. 缺少main方法,需要添加一个main方法。
修改后的代码如下:
package java3_26;
public class Triangle {
private double sideA;
private double sideB;
private double sideC;
public Triangle(double sideA, double sideB, double sideC) {
this.sideA = sideA;
this.sideB = sideB;
this.sideC = sideC;
}
public double getSideA() {
return sideA;
}
public void setSideA(double sideA) {
this.sideA = sideA;
}
public double getSideB() {
return sideB;
}
public void setSideB(double sideB) {
this.sideB = sideB;
}
public double getSideC() {
return sideC;
}
public void setSideC(double sideC) {
this.sideC = sideC;
}
public double getArea() {
double p = (sideA + sideB + sideC) / 2.0;
return Math.sqrt(p * (p - sideA) * (p - sideB) * (p - sideC));
}
public double getPerimeter() {
return sideA + sideB + sideC;
}
public static void main(String[] args) {
Triangle triangle = new Triangle(3, 4, 5);
System.out.println("Area: " + triangle.getArea());
System.out.println("Perimeter: " + triangle.getPerimeter());
}
}
阅读全文