# What did i do wrong this time!

Show 40 post(s) from this thread on one page
Page 1 of 2 12 Last
• 01-19-2009, 07:08 AM
PureAwesomeness
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:
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); }         } }```
• 01-19-2009, 07:33 AM
angryboy
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.
• 01-19-2009, 07:47 AM
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.
• 01-19-2009, 07:50 AM
PureAwesomeness
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
• 01-19-2009, 07:51 AM
PureAwesomeness
Quote:

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?
• 01-19-2009, 07:53 AM
Eranga
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.
• 01-19-2009, 07:56 AM
Webuser
Quote:

if ((a + b > c) && (a + c > b) && (b + c > a)){
Maybe you should put down like a...
Quote:

(((a + b) > c)
Try it. By the way you didn't present error catch. Show it. That may clear the problem
• 01-19-2009, 08:03 AM
PureAwesomeness
that part works
i try your suggestion(Webuser) and didnt work
just this part doesnt display
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); }```
• 01-19-2009, 08:05 AM
Webuser
What error you IDE shows in its console?
• 01-19-2009, 08:06 AM
Webuser
I need error text. Present it here
• 01-19-2009, 08:08 AM
PureAwesomeness
it didnt show any error
it doesnt display on the command prompt
• 01-19-2009, 08:08 AM
Webuser
I have some suggestions but for more clear I need to see your IDE console error text. Publish it here
• 01-19-2009, 08:11 AM
Webuser
Is is simply just
Surround your code with try {/*code*/} catch(Exception e){System.out.println(e)}
And publish it here
• 01-19-2009, 08:13 AM
Webuser
Quote:

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
• 01-19-2009, 08:17 AM
Webuser
How you do? Is it work? I mean the command prom shows something like a "error is: ..."
• 01-19-2009, 08:24 AM
PureAwesomeness
i have not learn that code yet
and it gives me more errors...
• 01-19-2009, 08:25 AM
Webuser
What you mean "more errors" what errors?
• 01-19-2009, 08:26 AM
Webuser
Copy the errors text and paste them here
• 01-19-2009, 08:38 AM
angryboy
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.
• 01-19-2009, 08:45 AM
PureAwesomeness
';' expected
{catch(Exception e){System.out.println("error is: "+e)}

reached end of file while parsing
}

like these
Show 40 post(s) from this thread on one page
Page 1 of 2 12 Last