Page 1 of 2 12 LastLast
Results 1 to 20 of 29
  1. #1
    Join Date
    Jan 2009
    Posts
    90
    Rep Power
    0

    Default 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 06:12 AM.

  2. #2
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    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.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    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. #4
    Join Date
    Jan 2009
    Posts
    90
    Rep Power
    0

    Default

    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. #5
    Join Date
    Jan 2009
    Posts
    90
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    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. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    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. #7
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    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. #8
    Join Date
    Jan 2009
    Posts
    90
    Rep Power
    0

    Default

    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. #9
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    What error you IDE shows in its console?

  10. #10
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    I need error text. Present it here

  11. #11
    Join Date
    Jan 2009
    Posts
    90
    Rep Power
    0

    Default

    it didnt show any error
    it doesnt display on the command prompt

  12. #12
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    I have some suggestions but for more clear I need to see your IDE console error text. Publish it here

  13. #13
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    Is is simply just
    Surround your code with try {/*code*/} catch(Exception e){System.out.println(e)}
    And publish it here

  14. #14
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    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. #15
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    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 07:21 AM.

  16. #16
    Join Date
    Jan 2009
    Posts
    90
    Rep Power
    0

    Default

    i have not learn that code yet
    and it gives me more errors...

  17. #17
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    What you mean "more errors" what errors?

  18. #18
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    Copy the errors text and paste them here

  19. #19
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    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.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  20. #20
    Join Date
    Jan 2009
    Posts
    90
    Rep Power
    0

    Default

    ';' expected
    {catch(Exception e){System.out.println("error is: "+e)}

    reached end of file while parsing
    }

    like these

Page 1 of 2 12 LastLast

Similar Threads

  1. What did i do wrong
    By jpnym15 in forum New To Java
    Replies: 8
    Last Post: 11-17-2008, 10:07 AM
  2. what's wrong in here!!!
    By Annatar in forum New To Java
    Replies: 8
    Last Post: 11-14-2008, 02:55 AM
  3. So, what am I doing wrong?
    By Charles_Smith in forum New To Java
    Replies: 0
    Last Post: 10-29-2008, 02:50 PM
  4. right or wrong
    By jot321 in forum New To Java
    Replies: 7
    Last Post: 09-25-2008, 11:45 AM
  5. Replies: 21
    Last Post: 08-01-2008, 11:13 AM

Posting Permissions

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