我正在试图弄清楚如何将布尔方法调用为true或false。以下是我到目前为止的情况:
import java.util.Scanner;
import java.text.DecimalFormat;
public class AssignmentThree {
public static void main(String[]args) {
Scanner scan = new Scanner(System.in);
System.out.print("Enter the length of Edge 1: ");
double edge1 = scan.nextDouble();
System.out.print("Enter the length of Edge 2: ");
double edge2 = scan.nextDouble();
System.out.print("Enter the length of Edge 3: ");
double edge3 = scan.nextDouble();
scan.close();
DecimalFormat Dec = new DecimalFormat("###,###,##0.00");
if(isValid (edge1, edge2, edge3) == true) {
System.out.println("The area of the triangle is " + Dec.format(area(edge1, edge2, edge3)));
}
if(isValid (edge1, edge2, edge3) == false) {
System.out.println("This is not a valid traingle");
}
}
public static boolean isValid(double side1, double side2, double side3) {
//testing to see if the triangle is real
if(side1+side2>side3 || side1+side3>side2 || side2+side3>side1) {
return true;
} else {
return false;
}
}
我不确定问题是否在我的方法中,但是当程序运行时,它只是打印区域,而不管它是否有效。