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 3 of 3

Thread: letter pattern

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    11
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default letter pattern

    Desired output-
    ***   *           *
    *   *  *  *   *  *       
    *   *  *     *    * 
    *   *  *           *  
    ***   *           *
    these are the separate codes for D and M,now how to combine them to get the desired output,pls help
    CODE FOR M
    class a
    {
    public static void main(String args[])
    {
    int i,j;
    for(i=1;i<=5;i++)
    {
    for(j=1;j<=5;j++)
    {
     
    if(j==1 || j==5)
    System.out.print("*");
    else if(i==2 && (j==2 || j==4))
    System.out.print("*");
    else if(i==3 && j==3)
    System.out.print("*");
    else 
    System.out.print(" ");
    }
    System.out.println();
    }
    }
    }
     
    CODE FOR D
    class a
    {
    public static void main(String args[])
    {
    int i,j;
    for(i=1;i<=5;i++)
    {
    for(j=1;j<=4;j++)
    {
    if(j==1)
    System.out.print("*");
    else if((j==2 || j==3)&& i==1)
    System.out.print("*");
    else if((i==2 || i==3 ||i==4) && j==4)
    System.out.print("*");
    else if((j==2 || j==3)&& i==5)
    System.out.print("*");
    else 
    System.out.print(" ");
    }
    System.out.println();
     
    }
    }
    }
    Last edited by severus1; July 4th, 2011 at 12:47 PM.


  2. #2
    Junior Member
    Join Date
    Jun 2011
    Posts
    11
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: letter pattern

    the second letter is M,the pattern couldnt be copy pasted correctly

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

    Default Re: letter pattern

    Take a piece of grid paper and write down the pattern you want to print.
    Look at each line and see what is printed on that line. Count the spaces around the *s.

    Since the print & println work line by line, you'll have to print the first line of the first letter and the first line of the next letter and end with a println to move to the next line.
    Do the same for the next line: first letters stuff then next letters stuff then next line.
    Continue until the last line is printed.

  4. The Following User Says Thank You to Norm For This Useful Post:

    severus1 (July 5th, 2011)

Similar Threads

  1. Regular Expression pattern - complex pattern syntax
    By SmartAndy in forum Algorithms & Recursion
    Replies: 3
    Last Post: June 7th, 2011, 04:40 AM
  2. Random Letter problem please help!
    By xs4rdx in forum Java Theory & Questions
    Replies: 1
    Last Post: March 28th, 2010, 11:27 AM
  3. Sentence and Letter Count Program
    By velop in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 10th, 2010, 12:10 AM
  4. help with the logic on this letter grade program.
    By etidd in forum Loops & Control Statements
    Replies: 2
    Last Post: January 28th, 2010, 09:14 PM
  5. letter to number
    By silverspoon34 in forum Java Theory & Questions
    Replies: 1
    Last Post: November 27th, 2009, 07:01 AM