title: How should I reconfigure the arrow "->" to not print when done with with my pathing?
body: <p>I'm trying to create an optimal path to collect as many 1's as I can but after I execute my code, I still have an arrow pointing to nothing as there are no more places to go. How would I remove the arrow at the end of the code?</p>
  <pre><code>import java.util.Arrays;
  import java.util.Scanner;
  
  public class Main{
    public static void main(String[] args){
      Scanner s1 = new Scanner(System.in);
      int n = s1.nextInt();
      int m = s1.nextInt();
      int mat[][] = new int[n][m];
      for (int i = 0; i &lt; mat.length; i++){
        for (int j = 0; j &lt; mat[0].length; j++){
          mat[i][j] = s1.nextInt();
        } 
      }
      int path[][] = new int[n][m];
      for (int i = 0; i &lt; path.length; i++){
        Arrays.fill(path[i], -1);
      }
        
      int maxCoins = util(0, 0, mat, path);
      System.out.println(&quot;Max coins:&quot; + maxCoins);
        
      int row = 0, column = 0;
      System.out.print(&quot;Path:&quot;);
       
      while(row &lt; mat.length &amp;&amp; column &lt; mat[0].length){
        System.out.print(&quot;(&quot; + (row + 1) + &quot;,&quot; + (column + 1) + &quot;)&quot;);
        System.out.print(&quot;-&gt;&quot;);
        
        if(row &lt; n - 1 &amp;&amp; column &lt; m - 1){
          int down = path[row + 1][column];
          int right = path[row][column + 1];
          if(down &gt; right){
            row += 1;
            continue;
          }
          else if (right &gt; down){
            column += 1;
            continue;
          }
          else{
            row += 1;
            continue;
          }
        }
        if(row + 1 &lt; n){
          row += 1;
        }
        else{
          column += 1;
        }
      }
    }
    
    private static int util(int row,int column,int mat[][], int path[][]){
      if(row &gt;= mat.length || column &gt;= mat[0].length){
        return 0;
      }
      
      if(path[row][column]!= -1){
        return path[row][column];
      }
      
      int right = util(row, column + 1, mat,path);
      int down = util(row + 1, column, mat,path);
      
      path[row][column]=Math.max(right, down);
      if(mat[row][column] == 1){
        path[row][column] += 1;
      }
      
      return path[row][column];
    }
  }
  </code></pre>
  <p>My current input looks like:</p>
  <pre><code>5 6
  0 0 0 0 1 0
  0 1 0 1 0 0
  0 0 0 1 0 1
  0 0 1 0 0 1
  1 0 0 0 1 0
  </code></pre>
  <p>And output is:</p>
  <pre><code>Max coins:5
  Path:(1,1)-&gt;(2,1)-&gt;(2,2)-&gt;(2,3)-&gt;(2,4)-&gt;(3,4)-&gt;(3,5)-&gt;(3,6)-&gt;(4,6)-&gt;(5,6)-&gt;
  </code></pre>
  <p>I am just trying to remove the one at the end but unsure where to insert my code:</p>
  <pre><code>System.out.print(&quot;-&gt;&quot;);
  </code></pre>