pTutorial

New way to learn Programming

Simple array programs in java

1 2 3
4 5 6
7 8 9

Java program to print upper triangular matrix

public class PrintTringleUpperHalf {
    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=(i+1)-1;j<d[i].length;j++)
            {
                System.out.print(d[i][j]);
                System.out.print("\t");
            }
            System.out.println("");
        }
    }
}


Output

1	2	3	
5	6	
9	

See Also


QUOTES OF THE DAY

Eat to live, and not live for eat.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER