Results 1 to 7 of 7
  1. #1
    aspire007 is offline Member
    Join Date
    Jul 2010
    Posts
    4
    Rep Power
    0

    Exclamation Inverted Right Triangle help

    I have the code:

    Java Code:
    public class InvertedRightTri
    
    {
    
    public static void main(String[] args)
    
    {
    
    
    
       int a=1;
    
       int b;
    
       int c=5;
    
    
    
    do{
    
    
    
       b = a - 1;
    
    
    
        if (b!=0){
    
    
    
           do{
    
            System.out.print(" ");
    
            b--;
    
           }while(b >= 1);
    
        }
    
    b=1;
    
           do{
    
           System.out.print("*");
    
           b++;
    
           }while(b <= (c - a + 1));
    
    
    
    
    
     System.out.println();
    
     a++;
    
     }while(a <= c);
    
    
    
     }
    
    }
    and the output is:
    XML Code:
    *****
     ****
      ***
       **
        *
    need help another code for this using the do-while loop also.
    Please help me to all experts, i need your help as soon as possible. I'm new to java.
    Thanks for reply!
    Last edited by Eranga; 07-29-2010 at 06:41 AM. Reason: code tags added

  2. #2
    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

    What you have tried so far, show your effort here. Then we'll help you to comes out on what you've stuck.

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,562
    Rep Power
    25

    Default

    What is the problem you are trying to solve? What do you need help with?
    I don't see any questions in your post.

  4. #4
    Join Date
    Jul 2010
    Posts
    4
    Rep Power
    0

    Default

    I am not sure that I've understood your question.
    I may suggest that you notice the order of the loops, though.
    That's probably the key, if I got your question right.

  5. #5
    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

    May be OP wants to do this with for loops or something. My point is whatever the way he/she is not put some effort to do something.

  6. #6
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,655
    Blog Entries
    7
    Rep Power
    21

    Default

    Maybe the following little method will help:

    Java Code:
    public void printymbols(char s, int n) {
       for (int i= 0; i < n; i++)
          System.out.print(s);
    }
    The method prints 'n' symbols 's' on a line; the OP can now think in terms of printing symbols on a line ...

    kind regards,

    Jos

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

Similar Threads

  1. Triangle using Numbers
    By Anandt88 in forum New To Java
    Replies: 16
    Last Post: 06-05-2010, 04:10 PM
  2. ASCII Triangle
    By physics in forum New To Java
    Replies: 2
    Last Post: 03-13-2010, 01:00 AM
  3. triangle program
    By computerbum in forum New To Java
    Replies: 8
    Last Post: 03-02-2010, 04:55 AM
  4. Triangle
    By jkswebsite in forum New To Java
    Replies: 8
    Last Post: 01-10-2009, 02:08 PM
  5. Is it a right triangle? (Code help)
    By TheApostle in forum New To Java
    Replies: 8
    Last Post: 10-07-2008, 08:39 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
  •