Horizontal Repitition Of Plus-Pattern












2















I have to generate the following pattern:



https://imgur.com/p2xbj9Y



I have so far:



https://imgur.com/0RrIDh1



Having some duplicated lines in the pattern is also a problem, but currently has no high priority.
My problem is rather to repeat the pattern on the horizontal level.



This is the Code I have so far:



public class Pattern {

public static void main(String args) {

final char indentChar = ' ';
final char fillChar = '+';
int fillWidth;
int indentWidth;
int triangleBaseLength = 9;
int triangleHeight = (triangleBaseLength / 2) + 1;


int horizontalRepeats = 5;
int verticalRepeats = 2;

for (int y = 1; y <= verticalRepeats; y++) { //vertical Repeats

for (int i = 0; i < triangleHeight; i++) { //Top downwards
for (indentWidth = 0; indentWidth < triangleHeight * 0 + i; indentWidth++) {
System.out.print(indentChar);

}

for (fillWidth = 0; fillWidth < (triangleBaseLength - i * 2); fillWidth++) {
System.out.print(fillChar);

}

System.out.println();

}

for (int i = 1; i <= triangleHeight; i++) { //Top upwards
for (indentWidth = 0; indentWidth < triangleHeight * 1 - i; indentWidth++) {
System.out.print(indentChar);

}

for (fillWidth = 0; fillWidth < (i * 2 - 1); fillWidth++) {

System.out.print(fillChar);


}

System.out.println(); //vertical Repeats

}
}


}



To generate the horizontal epetition I tried the same with "(int y = 1; y <= horizontalRepeats; y++)" and "System.out.print();" but it does not work.
Is there an easy solution? I am not allowed to use more advanced stuff than this.










share|improve this question





























    2















    I have to generate the following pattern:



    https://imgur.com/p2xbj9Y



    I have so far:



    https://imgur.com/0RrIDh1



    Having some duplicated lines in the pattern is also a problem, but currently has no high priority.
    My problem is rather to repeat the pattern on the horizontal level.



    This is the Code I have so far:



    public class Pattern {

    public static void main(String args) {

    final char indentChar = ' ';
    final char fillChar = '+';
    int fillWidth;
    int indentWidth;
    int triangleBaseLength = 9;
    int triangleHeight = (triangleBaseLength / 2) + 1;


    int horizontalRepeats = 5;
    int verticalRepeats = 2;

    for (int y = 1; y <= verticalRepeats; y++) { //vertical Repeats

    for (int i = 0; i < triangleHeight; i++) { //Top downwards
    for (indentWidth = 0; indentWidth < triangleHeight * 0 + i; indentWidth++) {
    System.out.print(indentChar);

    }

    for (fillWidth = 0; fillWidth < (triangleBaseLength - i * 2); fillWidth++) {
    System.out.print(fillChar);

    }

    System.out.println();

    }

    for (int i = 1; i <= triangleHeight; i++) { //Top upwards
    for (indentWidth = 0; indentWidth < triangleHeight * 1 - i; indentWidth++) {
    System.out.print(indentChar);

    }

    for (fillWidth = 0; fillWidth < (i * 2 - 1); fillWidth++) {

    System.out.print(fillChar);


    }

    System.out.println(); //vertical Repeats

    }
    }


    }



    To generate the horizontal epetition I tried the same with "(int y = 1; y <= horizontalRepeats; y++)" and "System.out.print();" but it does not work.
    Is there an easy solution? I am not allowed to use more advanced stuff than this.










    share|improve this question



























      2












      2








      2








      I have to generate the following pattern:



      https://imgur.com/p2xbj9Y



      I have so far:



      https://imgur.com/0RrIDh1



      Having some duplicated lines in the pattern is also a problem, but currently has no high priority.
      My problem is rather to repeat the pattern on the horizontal level.



      This is the Code I have so far:



      public class Pattern {

      public static void main(String args) {

      final char indentChar = ' ';
      final char fillChar = '+';
      int fillWidth;
      int indentWidth;
      int triangleBaseLength = 9;
      int triangleHeight = (triangleBaseLength / 2) + 1;


      int horizontalRepeats = 5;
      int verticalRepeats = 2;

      for (int y = 1; y <= verticalRepeats; y++) { //vertical Repeats

      for (int i = 0; i < triangleHeight; i++) { //Top downwards
      for (indentWidth = 0; indentWidth < triangleHeight * 0 + i; indentWidth++) {
      System.out.print(indentChar);

      }

      for (fillWidth = 0; fillWidth < (triangleBaseLength - i * 2); fillWidth++) {
      System.out.print(fillChar);

      }

      System.out.println();

      }

      for (int i = 1; i <= triangleHeight; i++) { //Top upwards
      for (indentWidth = 0; indentWidth < triangleHeight * 1 - i; indentWidth++) {
      System.out.print(indentChar);

      }

      for (fillWidth = 0; fillWidth < (i * 2 - 1); fillWidth++) {

      System.out.print(fillChar);


      }

      System.out.println(); //vertical Repeats

      }
      }


      }



      To generate the horizontal epetition I tried the same with "(int y = 1; y <= horizontalRepeats; y++)" and "System.out.print();" but it does not work.
      Is there an easy solution? I am not allowed to use more advanced stuff than this.










      share|improve this question
















      I have to generate the following pattern:



      https://imgur.com/p2xbj9Y



      I have so far:



      https://imgur.com/0RrIDh1



      Having some duplicated lines in the pattern is also a problem, but currently has no high priority.
      My problem is rather to repeat the pattern on the horizontal level.



      This is the Code I have so far:



      public class Pattern {

      public static void main(String args) {

      final char indentChar = ' ';
      final char fillChar = '+';
      int fillWidth;
      int indentWidth;
      int triangleBaseLength = 9;
      int triangleHeight = (triangleBaseLength / 2) + 1;


      int horizontalRepeats = 5;
      int verticalRepeats = 2;

      for (int y = 1; y <= verticalRepeats; y++) { //vertical Repeats

      for (int i = 0; i < triangleHeight; i++) { //Top downwards
      for (indentWidth = 0; indentWidth < triangleHeight * 0 + i; indentWidth++) {
      System.out.print(indentChar);

      }

      for (fillWidth = 0; fillWidth < (triangleBaseLength - i * 2); fillWidth++) {
      System.out.print(fillChar);

      }

      System.out.println();

      }

      for (int i = 1; i <= triangleHeight; i++) { //Top upwards
      for (indentWidth = 0; indentWidth < triangleHeight * 1 - i; indentWidth++) {
      System.out.print(indentChar);

      }

      for (fillWidth = 0; fillWidth < (i * 2 - 1); fillWidth++) {

      System.out.print(fillChar);


      }

      System.out.println(); //vertical Repeats

      }
      }


      }



      To generate the horizontal epetition I tried the same with "(int y = 1; y <= horizontalRepeats; y++)" and "System.out.print();" but it does not work.
      Is there an easy solution? I am not allowed to use more advanced stuff than this.







      java loops printing






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 26 '18 at 18:31









      jaco0646

      5,07952846




      5,07952846










      asked Nov 20 '18 at 2:09









      OzymandiasOzymandias

      132




      132
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Firstly, you should also include the empty spaces at the right of the + symbols. This means that instead of 2 for loops to print out each line, you would have to add another for loop, which is a duplicate of the first for loop.



          Secondly, You would need to wrap these 3 for loops for another for loop to repeat horizontally.



          for (int i = 0; i < triangleHeight; i++) { //Top downwards

          for (int h = 0; h < horizontalRepeats; h++) {
          for (indentWidth = 0; indentWidth < triangleHeight * 0 + i; indentWidth++) {
          System.out.print(indentChar);
          }

          for (fillWidth = 0; fillWidth < (triangleBaseLength - i * 2); fillWidth++) {
          System.out.print(fillChar);
          }

          // Repeat the first for loop...
          for (indentWidth = 0; indentWidth < triangleHeight * 0 + i; indentWidth++) {
          System.out.print(indentChar);
          }
          }

          System.out.println();
          }


          This will, however, not solve the problem of extra lines. I'll let you figure that out yourself.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53385231%2fhorizontal-repitition-of-plus-pattern%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Firstly, you should also include the empty spaces at the right of the + symbols. This means that instead of 2 for loops to print out each line, you would have to add another for loop, which is a duplicate of the first for loop.



            Secondly, You would need to wrap these 3 for loops for another for loop to repeat horizontally.



            for (int i = 0; i < triangleHeight; i++) { //Top downwards

            for (int h = 0; h < horizontalRepeats; h++) {
            for (indentWidth = 0; indentWidth < triangleHeight * 0 + i; indentWidth++) {
            System.out.print(indentChar);
            }

            for (fillWidth = 0; fillWidth < (triangleBaseLength - i * 2); fillWidth++) {
            System.out.print(fillChar);
            }

            // Repeat the first for loop...
            for (indentWidth = 0; indentWidth < triangleHeight * 0 + i; indentWidth++) {
            System.out.print(indentChar);
            }
            }

            System.out.println();
            }


            This will, however, not solve the problem of extra lines. I'll let you figure that out yourself.






            share|improve this answer




























              0














              Firstly, you should also include the empty spaces at the right of the + symbols. This means that instead of 2 for loops to print out each line, you would have to add another for loop, which is a duplicate of the first for loop.



              Secondly, You would need to wrap these 3 for loops for another for loop to repeat horizontally.



              for (int i = 0; i < triangleHeight; i++) { //Top downwards

              for (int h = 0; h < horizontalRepeats; h++) {
              for (indentWidth = 0; indentWidth < triangleHeight * 0 + i; indentWidth++) {
              System.out.print(indentChar);
              }

              for (fillWidth = 0; fillWidth < (triangleBaseLength - i * 2); fillWidth++) {
              System.out.print(fillChar);
              }

              // Repeat the first for loop...
              for (indentWidth = 0; indentWidth < triangleHeight * 0 + i; indentWidth++) {
              System.out.print(indentChar);
              }
              }

              System.out.println();
              }


              This will, however, not solve the problem of extra lines. I'll let you figure that out yourself.






              share|improve this answer


























                0












                0








                0







                Firstly, you should also include the empty spaces at the right of the + symbols. This means that instead of 2 for loops to print out each line, you would have to add another for loop, which is a duplicate of the first for loop.



                Secondly, You would need to wrap these 3 for loops for another for loop to repeat horizontally.



                for (int i = 0; i < triangleHeight; i++) { //Top downwards

                for (int h = 0; h < horizontalRepeats; h++) {
                for (indentWidth = 0; indentWidth < triangleHeight * 0 + i; indentWidth++) {
                System.out.print(indentChar);
                }

                for (fillWidth = 0; fillWidth < (triangleBaseLength - i * 2); fillWidth++) {
                System.out.print(fillChar);
                }

                // Repeat the first for loop...
                for (indentWidth = 0; indentWidth < triangleHeight * 0 + i; indentWidth++) {
                System.out.print(indentChar);
                }
                }

                System.out.println();
                }


                This will, however, not solve the problem of extra lines. I'll let you figure that out yourself.






                share|improve this answer













                Firstly, you should also include the empty spaces at the right of the + symbols. This means that instead of 2 for loops to print out each line, you would have to add another for loop, which is a duplicate of the first for loop.



                Secondly, You would need to wrap these 3 for loops for another for loop to repeat horizontally.



                for (int i = 0; i < triangleHeight; i++) { //Top downwards

                for (int h = 0; h < horizontalRepeats; h++) {
                for (indentWidth = 0; indentWidth < triangleHeight * 0 + i; indentWidth++) {
                System.out.print(indentChar);
                }

                for (fillWidth = 0; fillWidth < (triangleBaseLength - i * 2); fillWidth++) {
                System.out.print(fillChar);
                }

                // Repeat the first for loop...
                for (indentWidth = 0; indentWidth < triangleHeight * 0 + i; indentWidth++) {
                System.out.print(indentChar);
                }
                }

                System.out.println();
                }


                This will, however, not solve the problem of extra lines. I'll let you figure that out yourself.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 20 '18 at 2:32









                JaiJai

                5,85811231




                5,85811231
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53385231%2fhorizontal-repitition-of-plus-pattern%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Guess what letter conforming each word

                    Port of Spain

                    Run scheduled task as local user group (not BUILTIN)