this is the exercise that I am currently working on:
Write a test program that reads three sides for a triangle and computes the area if the input is valid. Otherwise, it displays that the input is invalid.
package Chapter05; import java.util.Scanner; public class MyTriangle { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter three points for a triangle: "); double side1 = input.nextDouble(); double side2 = input.nextDouble(); double side3 = input.nextDouble(); area(side1,side2,side3); } public static boolean isValid(double side1, double side2, double side3) { if(side1 + side2 > side3 && side1 + side3 > side2 && side2 + side3 > side1) { return true; } else if(side1 + side2 < side3 || side1 + side3 < side2 || side2 + side3 < side1) { System.out.println("Invalid"); } return false; } public static double area(double side1, double side2, double side3) { double area = 0; if(isValid(side1,side2,side3)) { double S = (side1 + side2 + side3)/2; area = Math.sqrt(S * (S - side1)* (S - side2) * (S - side3)); } return area; } }
How do I pass the value in the method isValid to run the method Area? When ever I run my code and put in the values for Side1,Side2, and Side3 my program just says Build Successful