Results 1 to 4 of 4
- 04-08-2009, 12:54 AM #1
Member
- Join Date
- Feb 2009
- Posts
- 42
- Rep Power
- 0
[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; } }
- 04-08-2009, 01:05 AM #2
Look closely at
You want your code to say: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"); }
Java Code:if(isValid()){ bla, bla, bla... }
- 04-08-2009, 01:08 AM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,546
- Rep Power
- 11
> 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.)
- 04-08-2009, 01:08 AM #4
Member
- Join Date
- Feb 2009
- Posts
- 42
- Rep Power
- 0
Similar Threads
-
if statement help please!!
By soc86 in forum New To JavaReplies: 5Last Post: 12-02-2008, 02:56 PM -
If statement, please help??
By soc86 in forum New To JavaReplies: 5Last Post: 11-23-2008, 02:58 PM -
Help with if statement
By carl in forum New To JavaReplies: 1Last Post: 08-06-2007, 07:53 AM -
Statement or Prepared Statement ?
By paty in forum JDBCReplies: 3Last Post: 08-01-2007, 04:45 PM -
If Statement
By aDrizzle in forum New To JavaReplies: 4Last Post: 07-08-2007, 08:55 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks