Page 1 of 2 12 LastLast
Results 1 to 20 of 21
  1. #1
    AFstudent is offline Member
    Join Date
    Nov 2008
    Posts
    13
    Rep Power
    0

    Default [SOLVED] Help Me with Printing Asterisk Triangular

    Hello, I am new in Java Programming can somebody help me with printing this:

    *******
    ******
    *****
    ***
    **
    *
    and
    *
    **
    ***
    ****
    *****
    Last edited by AFstudent; 11-11-2008 at 04:48 AM.

  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
    19

  3. #3
    AFstudent is offline Member
    Join Date
    Nov 2008
    Posts
    13
    Rep Power
    0

    Default

    I have made this but i want the reverse of it that i really tried but couldn't.

    Thanks
    Last edited by AFstudent; 11-11-2008 at 06:43 AM.

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

    Default

    Here you are stating from the lower value,

    Java Code:
    for (int Star=1; Star<=X; Star++)
    this line effect to print one asterisk at the first time.

    Think to start from the maximum,

    int Star = row;

    But in next time you want to print 9, 8, 7.... How can it handle?

    int Star = (row - X);

    Because X define the current turn.

    Then what you have to do is, decrease the value rather increasing.

    Star--;

    The think about the condition. First time you want to print once, and so on. How????

    Star > 0



    Java Code:
            int row=10;
            
            for(int X=1; X<=row;X++) {
                for (int Star = (row - X); Star >0; Star--) {
                    System.out.print("*");
                }
                System.out.println();
            }

  5. #5
    AFstudent is offline Member
    Join Date
    Nov 2008
    Posts
    13
    Rep Power
    0

    Default

    Thanks Eranga,
    I did try those steps you mentioned but it printed like this without spaces

    *********
    ********
    *******
    ******
    *****
    ****
    ***
    **
    *

  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
    19

  7. #7
    AFstudent is offline Member
    Join Date
    Nov 2008
    Posts
    13
    Rep Power
    0

    Default

    I wanted something like this. after each row of stars there is a space is indented and decreased
    *******
    ******
    *****
    ***
    **
    *

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

  9. #9
    AFstudent is offline Member
    Join Date
    Nov 2008
    Posts
    13
    Rep Power
    0

    Default

    Working but no luck ?? ('-')

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

    Default

    What you have tried, post here to see. Mistakes make a huge different lol, try it on whatever you know.

  11. #11
    AFstudent is offline Member
    Join Date
    Nov 2008
    Posts
    13
    Rep Power
    0

    Default

    I did this but it is not as accurate as i wanted
    Last edited by AFstudent; 11-11-2008 at 06:42 AM.

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

    Default

    Again the way you are working is ok, but mess with how to find the correct index.

    Java Code:
            int row = 10;
            
            for(int X = 1; X <= row; X++) {
                for(int Spc = 1; Spc < X; Spc++) {
                    System.out.print(" ");
                }
                for (int Star = (row - X); Star > 0; Star--) {
                    System.out.print("*");
                }
                System.out.println();
            }

  13. #13
    AFstudent is offline Member
    Join Date
    Nov 2008
    Posts
    13
    Rep Power
    0

    Default

    Thanks you so much for the instructions

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

    Default

    Is that what you are expecting do in your code?

    If the question is solved, it's pleasure to help you and don't forget to mark the thread as solved.

  15. #15
    AFstudent is offline Member
    Join Date
    Nov 2008
    Posts
    13
    Rep Power
    0

    Default

    Hey Eranga,
    can you also put some hints on this one aswell
    *
    **
    ***
    ****
    *****

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

    Default

    Now you have to do the same thing. Start from the minimum, rather from the maximum.

    Java Code:
                for (int Star = 1; Star <= X; Star++) {
                    System.out.print("*");
                }
    See how index are change from maximum.

  17. #17
    AFstudent is offline Member
    Join Date
    Nov 2008
    Posts
    13
    Rep Power
    0

    Default

    Sovled Thanks

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

  19. #19
    AFstudent is offline Member
    Join Date
    Nov 2008
    Posts
    13
    Rep Power
    0

    Default

    How do i mark the thread as solved, is there a menue or button,
    i couldn't find it

  20. #20
    AFstudent is offline Member
    Join Date
    Nov 2008
    Posts
    13
    Rep Power
    0

Page 1 of 2 12 LastLast

Similar Threads

  1. Help in Printing
    By kirly in forum Advanced Java
    Replies: 3
    Last Post: 10-03-2011, 03:40 PM
  2. Printing Example
    By Java Tip in forum SWT
    Replies: 0
    Last Post: 07-11-2008, 04:41 PM
  3. Problem after Printing GUI.
    By coldblood22 in forum AWT / Swing
    Replies: 1
    Last Post: 04-05-2008, 02:43 PM
  4. asterisk java
    By abhi in forum New To Java
    Replies: 4
    Last Post: 01-22-2008, 07:09 AM
  5. Asterisk-Java 0.3
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 07-02-2007, 08:30 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
  •