Showing posts with label sum of diagonals. Show all posts
Showing posts with label sum of diagonals. Show all posts

Wednesday, March 24, 2010

Sum Of Double Dimensional Array Diagonals

import java.io.*;

public class sumofdiagonals
{ public static void main(String args[]) throws IOException
{ InputStreamReader read = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(read);

int arr[][] = {{6,9,0,8},{3,2,1,5},{2,9,0,1},{4,1,9,6}};
int sum=0;
for(int i=0;i<4;i++)
{ for(int j=0;j<4;j++)
{ if(i==j)
sum+=arr[i][j];
}
}
System.out.println(sum);
}
}