Java program to print the right half star pyramid pattern
KW.java
class KW
{
    public static void main(String args[])
    {
        int i,j;
        for(i=1;i<=10;i++)
        {
            for(j=1;j<=i;j++)
            {
                System.out.print("*");
            }
            System.out.println("");
        }

        /*
        for(i=10;i>=1;i--)
        {
            for(j=10;j>=i;j--)
            {
                System.out.print((char)42);
            }
            System.out.println("");
        }
        */
    }
}
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW * ** *** **** ***** ****** ******* ******** ********* ********** kodingwindow@kw:~$
Java program to print the left half star pyramid pattern
KW.java
class KW
{
    public static void main(String args[])
    {
        int i,j;
        for(i=1;i<=10;i++)
        {
            for(j=1;j<=10-i;j++)
                System.out.print(" ");
                for(j=1;j<=i;j++)
                {
                    System.out.print("*");
                }
                System.out.print("\n");
        }
    }
}
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW * ** *** **** ***** ****** ******* ******** ********* ********** kodingwindow@kw:~$
Java program to print the inverted right half star pyramid pattern
KW.java
class KW
{
    public static void main(String args[])
    {
        int i,j;
        for(i=10;i>=1;i--)
        {
            for(j=1;j<=i;j++)
            {
                System.out.print("*");
            }
            System.out.println("");
        }
    }
}
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW ********** ********* ******** ******* ****** ***** **** *** ** * kodingwindow@kw:~$
Java program to print the inverted left half star pyramid pattern
KW.java
class KW
{
    public static void main(String args[])
    {
        int i,j;
        for(i=10;i>=1;i--)
        {
            for(j=1;j<=10-i;j++)
                System.out.print(" ");
                for(j=1;j<=i;j++)
                {
                    System.out.print("*");
                }
                System.out.print("\n");
        }
    }
}
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW ********** ********* ******** ******* ****** ***** **** *** ** * kodingwindow@kw:~$
Java program to print the half star pyramid pattern
KW.java
class KW
{
    public static void main(String args[])
    {
        int i,j;
        for(i=1;i<=10;i++)
        {
            for(j=1;j<=10-i;j++)
                System.out.print(" ");
                for(j=1;j<=i;j++)
                {
                    System.out.print("*"+" ");
                }
                System.out.print("\n");
        }
    }
}
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * kodingwindow@kw:~$
Java program to print the inverted half star pyramid pattern
KW.java
class KW
{
    public static void main(String args[])
    {
        int i,j;
        for(i=10;i>=1;i--)
        {
            for(j=1;j<=10-i;j++)
                System.out.print(" ");
                for(j=1;j<=i;j++)
                {
                    System.out.print("*"+" ");
                }
                System.out.print("\n");
        }
    }
}
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * kodingwindow@kw:~$
Java program to print the diamond star pyramid pattern
KW.java
class KW
{
    public static void main(String args[])
    {
        int i,j;
        for(i=1;i<=10;i++)
        {
            for(j=1;j<=10-i;j++)
                System.out.print(" ");
                for(j=1;j<=i;j++)
                {
                    System.out.print("*"+" ");
                }
                System.out.print("\n");
        }

        for(i=9;i>=1;i--)
        {
            for(j=1;j<=9-i;j++)
                System.out.print(" ");
                for(j=1;j<=i;j++)
                {
                    System.out.print(" *");
                }
                System.out.print("\n");
        }
    }
}
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * kodingwindow@kw:~$
Java program to print the pyramid pattern using natural numbers
KW.java
class KW
{
    public static void main(String args[])
    {
        int k=1;
        for(int i=1;i<10;i++)
        {
            for(int j=1;j<=i;j++,k++)
            {
                System.out.print(k+" ");
            }
            System.out.println(" ");
        }
    }
}
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 kodingwindow@kw:~$
Advertisement