Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: printing the pattern

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation printing the pattern

    i want to know how to print this type of pattern when a name is given ???
    example:

    name given TEJA

    Capture.PNG


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: printing the pattern

    Welcome to the Forum! Please read this topic to learn how to post code correctly and other useful tips for newcomers.

    This is an interesting twist on ascii art that I haven't seen before. In general, it is accomplished with for loops, probably at least 2 loops - one nested in the other - but there may be helper loops in addition to those. You'll need to do some math up front. Determine how many lines there are (the outside loop), how many columns there are (the inside loop), and in this case you'll need to think about and calculate spacing for the spokes. When you've gotten that figured out just using pencil and paper for the example name you've given, then consider what might happen if the name input is a five-letter (or some odd number) name instead of an even number. How will that change the resulting pattern and the math involved?

    After you have that roughed out, start coding. You might start by simply coding the pattern you've shown us using 4 asterisks as a constant name. Once you have that figured out, then move to substituting user input characters for the string of asterisks.

    Good luck!

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: printing the pattern

    Start by taking a piece of graph paper and drawing the pattern on it.
    Then look at what is printed on each line starting at the top.
    The code will need to print a line for each line on the graph paper.
    For each line that is to be printed, work out the spacing between each letter that is printed on that line.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Member
    Join Date
    Feb 2014
    Posts
    180
    Thanks
    0
    Thanked 48 Times in 45 Posts

    Default Re: printing the pattern

    +1 on starting with pencil and graph/squared paper. I would've done the same myself. If you don't have such paper at hand, you can go to Squared paper to download and print it yourself.

    For good results, I'd also recommend using a monospaced font such as Courier, Courier New and Lucida Console on the display console (in your IDE or Windows command prompt) so that you get consistent spacing between letters.

Similar Threads

  1. pattern
    By AJAY KAMBLE in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 16th, 2014, 04:21 AM
  2. Replies: 1
    Last Post: September 28th, 2011, 07:29 AM
  3. Pattern printing in Java
    By arunjib in forum Loops & Control Statements
    Replies: 4
    Last Post: July 1st, 2011, 04:05 PM
  4. Regular Expression pattern - complex pattern syntax
    By SmartAndy in forum Algorithms & Recursion
    Replies: 3
    Last Post: June 7th, 2011, 04:40 AM
  5. [SOLVED] Printing Array without printing empty elements
    By CarlMartin10 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 12th, 2010, 02:41 AM