lundi 19 novembre 2018

Horizontal Repitition Of Plus-Pattern

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.

Aucun commentaire:

Enregistrer un commentaire