Results 1 to 4 of 4
  1. #1
    leonardjr is offline Member
    Join Date
    Feb 2009
    Posts
    42
    Rep Power
    0

    Default [SOLVED] Need help with an if statement

    I need the if statement to work if the isValid statement comes back true but i'm getting an error saying it can't fing the isValid statement... what am I doing wrong?

    Java Code:
    import java.util.Scanner;
    
    public class CheckTriangles {
    
        public static void main(String[] args) {
        
        Scanner input=new Scanner(System.in);
        
        //Prompt user to enter side values
        System.out.print("Enter side 1 value: ");
        double side1=input.nextDouble();
        System.out.print("Enter side 2 value: ");
        double side2=input.nextDouble();
        System.out.print("Enter side 3 value: ");
        double side3=input.nextDouble();
        
        
        //invoke the isValid method with the double parameters
        System.out.println("The triangle is valid: " + isValid(side1,side2,side3));
        
        if(isValid=true){
        //invoke the area of the valid triangle
        System.out.println("The area is: " + area(side1,side2,side3));}
        else{
        	System.out.println("The triangle is invalid and therefore area cannot be found");
        }
        }
        public static boolean isValid(double side1, double side2, double side3){
        	if(side1+side2>side3&&side2+side3>side1&&side1+side3>side2)
        		return true;
        	else
        		return false;
        	}
       public static double area(double side1, double side2, double side3){
       	double s=(side1+side2+side3)/2;
       	double area=Math.sqrt(s*(s-side1)*(s-side2)*(s-side3));
       	return area;
       }
        
        }

  2. #2
    markw8500's Avatar
    markw8500 is offline Senior Member
    Join Date
    Jul 2008
    Location
    Pennsylvania, USA
    Posts
    136
    Rep Power
    0

    Default

    Look closely at
    Java Code:
       if(isValid=true){
        //invoke the area of the valid triangle
        System.out.println("The area is: " + area(side1,side2,side3));}
        else{
        	System.out.println("The triangle is invalid and therefore area cannot be found");
        }
    You want your code to say:

    Java Code:
    if(isValid()){
         bla, bla, bla...
    }

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    > but i'm getting an error saying it can't fing the isValid statement

    Does this compile? If not and you can't understand the compiler message, please post the exact message.
    Last edited by pbrockway2; 04-08-2009 at 01:09 AM. Reason: too slow ... (but the comment about posting compiler messages as an essential part of a problem description still stands.)

  4. #4
    leonardjr is offline Member
    Join Date
    Feb 2009
    Posts
    42
    Rep Power
    0

Similar Threads

  1. if statement help please!!
    By soc86 in forum New To Java
    Replies: 5
    Last Post: 12-02-2008, 02:56 PM
  2. If statement, please help??
    By soc86 in forum New To Java
    Replies: 5
    Last Post: 11-23-2008, 02:58 PM
  3. Help with if statement
    By carl in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 07:53 AM
  4. Statement or Prepared Statement ?
    By paty in forum JDBC
    Replies: 3
    Last Post: 08-01-2007, 04:45 PM
  5. If Statement
    By aDrizzle in forum New To Java
    Replies: 4
    Last Post: 07-08-2007, 08:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •