title: Removing the last comma
body: <p>I'm trying to remove the last comma from my print method. Is there a way to do this?
  Thank you.</p>
  
  <pre><code>    public void print() {
      for(int i = 0; i &lt; M.length; i++){
          for(int j = 0; j &lt; M[i].length; j++){
              System.out.print(M[i][j] + ",");
          }
          System.out.println();
      }
  
  }
  </code></pre>
  
  <p>Output:</p>
  
  <p>1.5,2.0,3.0,</p>
  
  <p>3.0,2.5,4.0,</p>
  
  <p>2.5,4.0,2.5,</p>
  
  <p>I ended up adding an "if" statement to solve the same problem.
  Here is how I ended up doing it:</p>
  
  <pre><code>    public void print() {
      for(int i = 0; i &lt; M.length; i++){
          for(int j = 0; j &lt; M[i].length; j++){
              if(j == M[i].length-1){
                  System.out.print(M[i][j] +" ");
              }
              else{
                  System.out.print(M[i][j] + ",");
              }
          }
          System.out.println();
      }
  
  }
  </code></pre>
  
  <p>Output:</p>
  
  <p>1.5,2.0,3.0</p>
  
  <p>3.0,2.5,4.0 </p>
  
  <p>2.5,4.0,2.5 </p>