Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class JavaApplication6{
- public static int diagonalCount(int [][]arr){
- int len = arr.length;
- int total = 0;
- for(int i = 0; i < len; i++){
- total += arr[i][i];
- }
- return total;
- }
- public static int lowerCount(int [][]arr){
- int len = arr.length;
- int total = 0;
- for(int i = 0; i < len; i++){
- for(int j =0; j < len; j++){
- if(j < i){
- total += arr[i][j];
- }
- }
- }
- return total;
- }
- public static void main(String[] args) {
- int [][]arr = {{1,2,3},{4,5,6},{7,8,9}};
- System.out.println(diagonalCount(arr));
- System.out.println(lowerCount(arr));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement