Pattern

class Q3apage246{
    public static void main(String ar[]){
        int n=4;
        int a[][]=new int [n][];
        int c=0;
        for(int i=0;i<n;i++){
            a[i]=new int[i+1];
            for(int j=0;j<n;j++){
                if(j<=i){
                    a[i][j]=c;
                    c++;
                }
            }
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                    if(j<=i){
                     System.out.print(a[i][j]);
                    }
            }
            System.out.println("");
        }
    }
}

OUTPUT
0
12
345
6789

No comments:

Popular Posts