Activity

  • priya sharma posted an update in the group Group logo of java Programmerjava Programmer 1 week ago  · 

    Program for Diagonal Difference of matrix- java
    —–************************——–
    import java.io.*;
    import java.util.*;

    public class Solution {

    public static void main(String[] args) {
    Scanner scan=new Scanner(System.in);
    int p = scan.nextInt();
    int [][]d = new int [p][p];

    for(int i=0;i<d.length;i++)
    {
    for(int l=0;l<d.length;l++){
    d[i][l]=scan.nextInt();
    }
    }
    int k = 0, j = 0;
    int sum1 = 0, sum2 = 0, sum=0;
    for (j = 0; j < d.length; j++) {
    for (k = 0; k < d.length; k++){

    }
    System.out.print(d[j][k] + " ");
    System.out.println();
    }
    for (j = 0; j < d.length; j++) {
    sum1 = sum1 + d[j][j];
    }
    k = d.length – 1;
    for (j = 0; j = 0) {
    sum2 = sum2 + d[j][k];

    k–;
    }
    }
    sum=sum1-sum2;
    System.out.println(Math.abs(sum));
    }
    }