0

我试图弄清楚如何将布尔方法调用为真或假。到目前为止,这是我所拥有的:

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;
    }
}

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

4

0 回答 0