Creative triangle stacks using for loops I was wondering if someone can help me out with achieving the following result (using for loops):


|../\..../\..|
|./\/\../\/\.|
|/\/\/\/\/\/\|


This is the code that I have written:

public static void drawBody1(){
  for (int line = 1; line &lt;= 3; line++){
      System.out.print("|");
      for (int dot = 1; dot &lt;= (-1 * line + 3); dot++){
        System.out.print(".");
      }
      for (int mount = 1; mount &lt;= line; mount++){
        System.out.print("/\\");
      }
      for (int dot = 1; dot &lt;= (-2 * line + 6); dot++){
        System.out.print(".");
      }
      for (int mount = 1; mount &lt;= line; mount++){
        System.out.print("/\\");
      }
      for (int dot = 1; dot &lt;= (-1 * line + 3); dot++){
        System.out.print(".");
      }
      System.out.print("|");
      System.out.println();
  }


Although I did get the figure above, I realize that the code abounds in redundancy and is, thus, far from efficient. 

I was hoping if someone can show me a simple yet elegant solution to this problem.
I created a method, so it is easy to adjust the height of the pyramid, and the output it gives is just as you asked. This code is shorter and easier to understand in my opinion(maybe just because I wrote it), but the main difference is that it is easy to change the height of your pyramid. I named my function drawMounts(int height). Try changing height in the main method, and you will see that the pyramids easily adjust. This program makes one line at a time, prints it and repeats but the line changes slightly. height can be even or odd, it works the same. Here's the program:

public class Experiments {  
    public static void main(String[] args) {
        drawMounts(3);
    }
    private static void drawMounts(int height) {
        for (int i = 0; i &lt; height; i++) {
            String line = "";
            String ends = "";
            String middle = ".";
            String mount = "";
            System.out.print("|");
            for(int j = i; j &lt; (height-1); j++)
                middle += "..";
            for (int dot = i; dot &lt; (height-1); dot++)
                ends += ".";
            for(int body = (i+1); body &gt; 0; body--)
                mount += "/\\";
            line = ends + mount + middle + mount + ends;
            System.out.print(line);
            System.out.println("|");
        }   
    }
}


And here's the output when height is equal to 3:

|../\..../\..|
|./\/\../\/\.|
|/\/\/\/\/\/\|


And this is when height is 6, just so you get an idea of what changing height does:

|...../\........../\.....|
|..../\/\......../\/\....|
|.../\/\/\....../\/\/\...|
|../\/\/\/\..../\/\/\/\..|
|./\/\/\/\/\../\/\/\/\/\.|
|/\/\/\/\/\/\/\/\/\/\/\/\|