package edward;
public class Triangle{
double sideA,sideB,sideC;
boolean isTriangle;
public Triangle(double a,double b,double c){
if(a+b>c&&b+c>a&&a+c>b){
isTriangle=ture;
}
else{
isTriangle=flase;
}
public void 计算面积{
if(isTriangle){
double p=(sideA+sideB+sideC)/2.0;
double area=Math.sqrt(p*(p-sideA)*(p-sideB)*(p-sideC));
System.out.println("是一个三角形,面积为:"+area);
}
else{
System.out.println("不是一个三角形,不能计算面积");
}
public void 修整三边(double a,double b,double c){
sideA=a;
sideB=b;
sideC=c;
if(a+b>c&&a+c>b&&b+c>a){
isTriangle=ture;
}
else{
isTriangle=flase;
}
}
}
import edward.Triangle;
public class Example4_14{
public static void main(String args[]){
Triangle tri=new Triangle(3,4,5);
tri.计算面积();
tri.修整三边(4,5,6);
tri.计算面积();
}
}
------解决方案--------------------
少了闭合的} 还有中文名字!
------解决方案--------------------
错误百出!
都是小错误,这种错误LZ因该学会自已解决,这是必须的!
另外中文可以,只是不符合JAVA编程规范。
------解决方案--------------------
public class Triangle {
double sideA, sideB, sideC;
boolean isTriangle;
public Triangle(double a, double b, double c) {
this.sideA = a;
this.sideB = b;
this.sideC = c;
if (a + b > c && b + c > a && a + c > b) {
isTriangle = true;
} else {
isTriangle = false;
}
}
public void 修整三边(double a, double b, double c) {
sideA = a;
sideB = b;
sideC = c;
if (a + b > c && a + c > b && b + c > a) {
isTriangle = true;
} else {
isTriangle = false;
}
}
public void 计算面积() {
if (isTriangle) {
double p = (sideA + sideB + sideC) / 2.0;
double area = Math
.sqrt(p * (p - sideA) * (p - sideB) * (p - sideC));
System.out.println("是一个三角形,面积为:" + area);
} else {
System.out.println("不是一个三角形,不能计算面积");
}
}
}