title: Triangular matrix get() in one dimensional array
body: <p>I want to save a triangular matrix in a 1 dim array (to minimize needed space, all zeros are left out) and create a function <code>get()</code> to find a specific entry from the original matrix. </p>
  
  <p>For example:</p>
  
  <p>Lets look at the following triangular matrix :</p>
  
  <pre><code>0 1 2 3 
  0 0 4 5 
  0 0 0 6 
  0 0 0 0
  </code></pre>
  
  <p>I am saving this matrix like this: </p>
  
  <pre><code>double[] test = {1,2,3,4,5,6};
  </code></pre>
  
  <p>So all the zeros are left out.</p>
  
  <p>I want to write a function that gives me a value of the original matrix:</p>
  
  <pre><code>get(3,4)
  </code></pre>
  
  <p>should give me <code>6</code></p>
  
  <p>I am checking the input to see if its out of bound and if it is below or on the diagonal. </p>
  
  <pre><code>//Checking if input is valid 
          if (i &lt;= n &amp;&amp;  j &lt;= n &amp;&amp; i &gt;= 1 &amp;&amp; j &gt;= 1){
              if( j &lt;= i ){
                  return 0.0;
              }else {
  
              }
          }
  </code></pre>
  
  <p>This works.</p>
  
  <p>How do I proceed though? I have trouble finding the equivalent matrix entry in my array. </p>
  
  <p>Any help would be appreciated.</p>
  
  <p>EDIT: </p>
  
  <p>My whole code: </p>
  
  <pre><code>public class dreiecksmatrix {
      int n = 4;
      double[] a = {1,2,3,4,5,6};
  
      public double get( int i, int j){
  
          //Checking if input is valid 
          if (i &lt;= n &amp;&amp;  j &lt;= n &amp;&amp; i &gt;= 0 &amp;&amp; j &gt;= 0){
              if( j &lt;= i ){
                  return 0.0;
              }else {
  
              }
          }
  
          return 1.0;
      }
  
      public static void main(String [] args ){
          dreiecksmatrix test = new dreiecksmatrix();
          System.out.println(test.get(2,3));
  
      }
  }
  </code></pre>