Results 1 to 3 of 3

Thread: Create Pattern

  1. #1
    bossanova is offline Member
    Join Date
    Oct 2010
    Posts
    8
    Rep Power
    0

    Default Create Pattern

    I've actually been working on this same problem, and I've been having trouble as well. Though I've found out the pattern is supposed to consist of two triangles like this:

    1 333
    22 22
    333 1
    4444

    Also, we're only supposed to use nested loops. Strings are not allowed. So far I have this:

    for (int k = 0; k <= 2; k++){
    for (int n = 0; n <= 1 * k; n++){
    System.out.print(" ");
    }
    for (int m = 2; m>= k; m--){
    System.out.print((3-k));
    }
    System.out.println();

    }
    for (int i = 0; i <= 3; i++){ //1
    for (int j = 0; j <=i; j++){ //22
    System.out.print(1 + i); //333
    } //4444
    System.out.println();
    }

    }}

    Which produces this:

    333
    22
    1
    1
    22
    333
    4444

    The spacing on the top triangle should be correct. Is there a way to combine the two? I've messed around with the brackets but nothing seems to be working.

    Edit: Sorry about that, Fubarable.
    Last edited by bossanova; 10-12-2010 at 02:22 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    OP, please do not hijack other's posts. If you've a question related to another thread, then start your own thread and provide a link to the related one. I've moved your post from this thread most-my-trouble-identifying-pattern into its own thread.

  3. #3
    bossanova is offline Member
    Join Date
    Oct 2010
    Posts
    8
    Rep Power
    0

Similar Threads

  1. Class pattern to generate following pattern:-
    By vxs in forum New To Java
    Replies: 5
    Last Post: 07-14-2010, 11:15 PM
  2. Create an Asterisk Pattern in Java
    By kaurpower in forum New To Java
    Replies: 1
    Last Post: 03-17-2010, 01:00 AM
  3. Pattern
    By mtyoung in forum Advanced Java
    Replies: 9
    Last Post: 04-07-2009, 02:17 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
  •