# Passing a boolean value through a method?

• November 29th, 2013, 01:15 AM
Mr.JavaNoob
Passing a boolean value through a method?
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.

Code :

```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
• November 29th, 2013, 01:23 AM
ChristopherLowe
Re: Passing a boolean value through a method?
Questions? Problems?
• November 29th, 2013, 04:28 AM
GregBrannon
Re: Passing a boolean value through a method?
You use an 'if' statement:
Code java:

```if ( resultsOfFirstMethod ) { area(); }```
• November 29th, 2013, 05:22 AM
Mr.JavaNoob
Re: Passing a boolean value through a method?
Quote:

Originally Posted by GregBrannon
You use an 'if' statement:
Code java:

```if ( resultsOfFirstMethod ) { area(); }```

Sorry, I don't quite understand
• November 29th, 2013, 05:57 AM
GregBrannon
Re: Passing a boolean value through a method?
Expanding it for you:
Code :

``` if ( isValid( side1, side2, side3 ) ) { area(side1,side2,side3); }```
• November 29th, 2013, 12:21 PM
Mr.JavaNoob
Re: Passing a boolean value through a method?
Thanks Greg I got it. looks like I was forgetting System.out.println(area); Thanks a lot.
• November 29th, 2013, 12:39 PM
GregBrannon
Re: Passing a boolean value through a method?
Ahhh. Glad to help. You're welcome.