title: Square pattern java
body: <p>Create void method that will put on screen square with patern like that :  </p>
  
  <pre><code>  xoxo  
    xoxo   
    xoxo   
    xoxo
  </code></pre>
  
  <p>First argument of the method will define amount of characters used to create a square side, second which character is first.    </p>
  
  <p>This is my solution but im wondering if i can do it with less code.  </p>
  
  <pre><code>static void square(char a, int b) {
   if (a == 'x') {
          for (int i = 0; i &lt; b; i++) {
  
              int sum = 0;
              do {
  
  
                  System.out.print("x");
                  sum++;
                  if (sum == b)
                      break;
                  System.out.print("o");
                  sum++;
  
              }
              while (sum != b);
  
              System.out.println();
          }
  
      } else {
          for (int i = 0; i &lt; b; i++) {
  
              int sum = 0;
              do {
  
  
                  System.out.print("o");
                  sum++;
                  if (sum == b)
                      break;
                  System.out.print("x");
                  sum++;
  
              }
              while (sum != b);
  
              System.out.println();
          }
      }
  }
  </code></pre>
  
  <p>How to make pattern to look like </p>
  
  <pre><code>xoxox
  oxoxo
  xoxox
  oxoxo
  xoxox
  </code></pre>
  
  <p>And how to make this using only for loops or arrays.</p>