# Thread: What did i do wrong this time!

1. Member
Join Date
Jan 2009
Posts
90
Rep Power
0

## What did i do wrong this time!

what did i do wrong?!
this program stops at the perimeter and doesn't proceed to accending part:mad:
Java Code:
```import java.util.Scanner;

public class HW {

public static void main (String[] args) {

Scanner input = new Scanner(System.in);

System.out.println("Enter the first edges of a triangle ");
int a = input.nextInt();

System.out.println("Enter the seond edges of a triangle ");
int b = input.nextInt();

System.out.println("Enter the seond edges of a triangle ");
int c = input.nextInt();

if ((a + b > c) && (a + c > b) && (b + c > a)){

System.out.println( a +","+ b+"," + c + ","+ "The input is  valid."  );
System.out.println("The perimeter: " +(a+b+c));
}
else{

System.out.println(a +","+ b +","+ c +","+"The input not valid.");
}
if ((a<b) && (b<c)){
System.out.println("The inputs in ascending order: "+a+b+c);
}
else if ((b<a) && (a<c)){
System.out.println("The inputs in ascending order: "+b+a+c);
}
else if ((c<a) && (a<b)){
System.out.println("The inputs in ascending order: "+c+a+b);
}
else if ((a<c) && (c<b)){
System.out.println("The inputs in ascending order: "+a+c+b);
}
else if ((b<c) && (c<a)){
System.out.println("The inputs in ascending order: "+b+c+a);
}
else if ((c<b) && (b<a)){
System.out.println("The inputs in ascending order: "+c+b+a);
}
}
}```
Last edited by PureAwesomeness; 01-19-2009 at 07:12 AM.

2. Don't understand what you are trying to do or the results you want. But its most likely some logic with the conditions. so check the math, make sure everythings calculated correctly on paper.

3. Ya, seems to me like that. You have several if-else conditions there in your code. May be it can cause to misses the logic.

4. Member
Join Date
Jan 2009
Posts
90
Rep Power
0
i want this program to display
first edge
second edge
third edge
the triangle vaild or not
the perimeter
(and the accending order) the program did not proceed to this part.

and i cant find my mistakes at

5. Member
Join Date
Jan 2009
Posts
90
Rep Power
0
Originally Posted by Eranga
Ya, seems to me like that. You have several if-else conditions there in your code. May be it can cause to misses the logic.
what do you suggest me to do?

6. First of all write your logic on a paper as pseudo code. It's really helpful to find what happen there in your code.

Or else just debug the code and see what happen. Put a break point at the start and move step by step.

7. Senior Member
Join Date
Dec 2008
Posts
526
Rep Power
0
if ((a + b > c) && (a + c > b) && (b + c > a)){
Maybe you should put down like a...
(((a + b) > c)
Try it. By the way you didn't present error catch. Show it. That may clear the problem

8. Member
Join Date
Jan 2009
Posts
90
Rep Power
0
that part works
i try your suggestion(Webuser) and didnt work
just this part doesnt display
Java Code:
```		if ((a<b) && (b<c)){
System.out.println("The inputs in ascending order: "+a+b+c);
}
else if ((b<a) && (a<c)){
System.out.println("The inputs in ascending order: "+b+a+c);
}
else if ((c<a) && (a<b)){
System.out.println("The inputs in ascending order: "+c+a+b);
}
else if ((a<c) && (c<b)){
System.out.println("The inputs in ascending order: "+a+c+b);
}
else if ((b<c) && (c<a)){
System.out.println("The inputs in ascending order: "+b+c+a);
}
else if ((c<b) && (b<a)){
System.out.println("The inputs in ascending order: "+c+b+a);
}```

9. Senior Member
Join Date
Dec 2008
Posts
526
Rep Power
0
What error you IDE shows in its console?

10. Senior Member
Join Date
Dec 2008
Posts
526
Rep Power
0
I need error text. Present it here

11. Member
Join Date
Jan 2009
Posts
90
Rep Power
0
it didnt show any error
it doesnt display on the command prompt

12. Senior Member
Join Date
Dec 2008
Posts
526
Rep Power
0
I have some suggestions but for more clear I need to see your IDE console error text. Publish it here

13. Senior Member
Join Date
Dec 2008
Posts
526
Rep Power
0
Is is simply just
Surround your code with try {/*code*/} catch(Exception e){System.out.println(e)}
And publish it here

14. Senior Member
Join Date
Dec 2008
Posts
526
Rep Power
0
try{
if ((a<b) && (b<c)){
System.out.println("The inputs in ascending order: "+a+b+c);
}
else if ((b<a) && (a<c)){
System.out.println("The inputs in ascending order: "+b+a+c);
}
else if ((c<a) && (a<b)){
System.out.println("The inputs in ascending order: "+c+a+b);
}
else if ((a<c) && (c<b)){
System.out.println("The inputs in ascending order: "+a+c+b);
}
else if ((b<c) && (c<a)){
System.out.println("The inputs in ascending order: "+b+c+a);
}
else if ((c<b) && (b<a)){
System.out.println("The inputs in ascending order: "+c+b+a);
}
}
catch(Exception e){System.out.println("error is: "+e)}
That should work out

15. Senior Member
Join Date
Dec 2008
Posts
526
Rep Power
0
How you do? Is it work? I mean the command prom shows something like a "error is: ..."
Last edited by Webuser; 01-19-2009 at 08:21 AM.

16. Member
Join Date
Jan 2009
Posts
90
Rep Power
0
i have not learn that code yet
and it gives me more errors...

17. Senior Member
Join Date
Dec 2008
Posts
526
Rep Power
0
What you mean "more errors" what errors?

18. Senior Member
Join Date
Dec 2008
Posts
526
Rep Power
0
Copy the errors text and paste them here

19. haha, i was just about to hit the sack. webuser you are so funny. what sup with the one sentence per post. Do you use AIM alot?

Its not a syntax error, just the calculations isn't correct. So it skipped over the if-else statements that he wanted.

PA: try putting alot of: System.out.println("First IF:------");
into your program and see which line it skiped over. Debugging is no joke.

20. Member
Join Date
Jan 2009
Posts
90
Rep Power
0
';' expected
{catch(Exception e){System.out.println("error is: "+e)}

reached end of file while parsing
}

like these

Page 1 of 2 12 Last

#### Posting Permissions

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