Methods 调用布尔方法

Methods 调用布尔方法,methods,boolean,geometry,invoke,Methods,Boolean,Geometry,Invoke,我正试图找出如何调用布尔方法作为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 le

我正试图找出如何调用布尔方法作为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;
    }
}

我不确定问题是否出在我的方法中,但当程序运行时,它只会打印区域,而不会打印它是否有效

一个代码改进提示:每当你有“if xxx return true,else return false”这样的代码,并且你没有按照源代码文件的大小获得报酬时,你可以让它只是“return xxx”。你有没有使用调试器来完成这一步?或者至少,在main()中输入三个面的值后打印出来,也可以从isValid()内部打印出来,以确保它得到了您认为您给出的值。另一个提示(这是最重要的):main()中的第二个“if”是否可以替换为“else”,使其属于第一个“if”?感谢您的快速响应!就调试而言,我看了几眼,什么也没弄明白。我试着移动一些东西,用else替换if,但它只给了我一个语法错误。我找到了答案。将我的isValid if语句更改为&&isntead为| |。谢谢你的帮助,达伦!