title: Output one dimensional array as 2 dimensional in java
body: <p>I have to output the array with a maximum of 4 array values per line, but I can't figure out how to convert it to a 2 dimensional array. After the dashes is where I am having trouble. If I don't output it as a 2D array, how else would I restrict it to have only 4 values per line? </p>
  
  <pre><code>public class arrayExampleB{
    public static void main(String[] args){
  
    int[] x = {22, 12, 28, 4, 30, 59, 17, 82, 1, 99, 47, 2, 8, 20, 80};
  
    System.out.print("Pre-Swapped Array Set (linear): {");
       for(int i=0; i&lt;=x.length-1; i++){
          if(i&lt;x.length-1){
             System.out.print(x[i] + ", ");
          }
          else{System.out.print(x[i]);} 
       }
       System.out.print("}");
  
    int y = x.length-1;
    int temp = x[y];
    x[y] = x[1];
    x[1] = temp;
  
    int z = x.length-2;
    int temp2 = x[z];
    x[z] = x[0];
    x[0] = temp2;
  
    System.out.print("\nPost-Swapped Array Set (linear): {");
       for(int i=0; i&lt;=x.length-1; i++){
          if(i&lt;x.length-1){
             System.out.print(x[i] + ", ");
          }
          else{System.out.print(x[i]);} 
       }
       System.out.print("}");
  </code></pre>
  
  <p>//-------------------------------------------------------------</p>
  
  <pre><code>  int d = (x.length / 4) + (x.length % 4);
    int i = 0;
    int j = 0;
    int[][] t = new int[i][j];
  
    System.out.print("\nPre-Swapped Array Set (2D): {");
       for(i=0; i &lt;= 4; i++){
          for(j=0; j &lt; d; j++){
             System.out.print(t[i][j] + " ");
          }
          System.out.println();
       }
    System.out.print("}");
  
     }
  }
  </code></pre>