pTutorial

New way to learn Programming

Java array programs exercise

1 2 3
4 5 6
7 8 9

Java program to print sum of lower triangular matrix

class TringleLowerHalfSum{
    public static void main(String... z)
    {
        sum(new int[][] {{1,2,3},{4,5,6},{7,8,9}});
    }
    
    static void sum(int d[][]){
        int sum=0;
        for(int i=0;i<d.length;i++){
            for(int j=0;j<d[i].length;j++){
                if(j==i+1){
                    break;
                }
                sum=sum+d[i][j];
            }
        }
        System.out.println("sum="+sum);
    }
}


Output

sum=34

See Also


QUOTES OF THE DAY

Wonder is the first cause of philosophy.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER