title: Java Matrix Diagonal Difference bug
body: <p>The objective of the code is to find the difference between the sum of 2 opposite diagonals of a matrix. Code: </p>
  
  <pre><code>public static void main(String[] args) {
      Scanner scn=new Scanner(System.in);
      int N=scn.nextInt();
      int diag1=0;
      int diag2=0;
      int[][] matrix=new int[N][N];
      for(int i=0; i&lt;N; i++){
          for(int j=0; j&lt;N; j++){
              matrix[i][j]=scn.nextInt();
              System.out.print(" ");
          }
          System.out.println();
      }
      for(int i=0; i&lt;N; i++){
          for(int j=0; j&lt;N; j++){
              if(i==j)
                  diag1+=matrix[i][j];
                  //System.out.println(diag1);
          }
      }
      int counter1=0, counter2=N-1;
      for(int i=0; i&lt;N; i++){
          for(int j=0; j&lt;N; j++){
              if(i==counter1 &amp;&amp; j==counter2){
                  diag2+=matrix[i][j];
                  counter1++;
                  counter2--;
              }
  
          }
      }
      System.out.println(diag1); // used this for checking purpose
      System.out.println(diag2); // used this for checking purpose
      System.out.println(Math.abs(diag1-diag2));
  </code></pre>
  
  <p>
  I am getting the exact output, but still the test case at HackerRank shows the code as fail. Can someone explain why?
  <a href="https://www.hackerrank.com/challenges/diagonal-difference" rel="nofollow">THe code challenge is mentioned here</a>
  </p>
  
  <p>I got the output after removing all the extra print statements! </p>