PYRAMID

 



WAP TO PRINT THE PYRAMID.

   


public class Pyramid
{
    public static void main(String [] args) {
        int i,j;
        char ch= 'A';
        for(i=1;i<=3;++i) {
            for(j=1;j<=9;++j) {
                if((i+j)%2==0&&j>=i&&(i+j)>=6&&(j-i)<=4&&(j-i)>=0)
                    System.out.print(ch);
                else
                    System.out.print(" ");
            }
            System.out.println();
            ch++;
        }
        for(i=4;i<=5;++i) {
            for(j=1;j<=9;++j) {
                if((i+j)%2==0)
                    System.out.print(ch);
                else
                    System.out.print(" ");
            }
            System.out.println();
            ch++;
        }
    }
}





NOTE:
The above program has been designed on basis of the co-ordinate system. Where both the co-ordinates of both the axes start from 1.



by,
ANUBRATA DAS

Post a Comment

Please Select Embedded Mode To Show The Comment System.*

Previous Post Next Post

It looks like you're using an ad blocker. We rely on ads to keep our site free, please whitelist us!

Click here to continue

Please whitelist our site to continue enjoying our content.

Whitelist | Close