pattern in java..plz help..

Discussion in 'Java' started by tech_aks, Sep 19, 2010.

  1. tech_aks

    tech_aks New Member

    Joined:
    Apr 5, 2010
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    kolkata
    wAP IN JAVA TO PRINT THE FOLLOWING PATTERNS...
    Code:
    1}                                           2}  *           *
                                                       *       *
                                                         *   *
                 *                                         *
                *                                        *  *
               *                                        *    *
              *                                       *        *
             *                                      *            *
            *                                
    *      *
      *   *
         *
     
    Last edited by a moderator: Sep 20, 2010
  2. tech_aks

    tech_aks New Member

    Joined:
    Apr 5, 2010
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    kolkata
    wAP IN JAVA TO PRINT THE FOLLOWING PATTERNS...
    1} 2} * *
    * *
    * *
    * *
    * * *
    * * *
    * * *
    * * *
    *
    * *
    * *
    *
     
  3. virxen

    virxen Active Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    28
    separate the patterns.Try enclosing it in code tags.
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Done that in one post. OP you have the link to what virxen is talking about as well.
     
  5. virxen

    virxen Active Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    28
    imagine that the stars are elements of a char array what you get?

    1) array -->(9,14)

    2) array--->(8,14)


    one way is to make an array and fill it with the stars and print it.

    another way is to use for loops (check the size of the arrays above)
    then you split the pattern line per line
    and for 2) you say
    Code:
    for (int i=0;i<8;i++){//lines
    String outputString=.....
    ..........
    System.out.println(outputString);
    }
    now split the line into parts.
    i=1 ---> "* *" print 1 * ,then print 12 spaces,then print 1 * (=1+12+1=14 characters)
    i=2----> " * * " print 1 space,then 1 *,then 10 spaces,then print 1 *,then print 1 space =14 chars
    i=3----->" * * " print 2 spaces,then 1 *,then 8 spaces then 1*,then print 2 spaces =14 chars

    ......
    do all of this and find the logic and finally the way to do it.

    send your tries here to help you.
     
    shabbir likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice