Programming Examples

Java program for pattern printing


Write a Java program to print Following Pattern:

Solution

class Pattern
{
    public static void main(String arr[])
    {
        int a,b;
        for(a=1;a<=5;a++)
        {
            for(b=1;b<=a;b++)
            {
                System.out.print("*");
            }
            System.out.println();
        }
    }
}
Output


Write a Java program to print Following Pattern:

Solution

class Pattern
{
    public static void main(String arr[])
    {
        int a,b;
        for(a=1;a<=5;a++)
        {
            for(b=5;b>=a;b--)
            {
                System.out.print("*");
            }
            System.out.println();
        }
    }
}
Output


Write a Java program to print Following Pattern:

Solution

class Pattern
{
    public static void main(String arr[])
    {
        int a,b;
        for(a=1;a<=5;a++)
        {
            for(b=5;b>=a;b--)
            {
                System.out.print(b);
            }
            System.out.println();
        }
    }
}
Output


Write a Java program to print Following Pattern:

Solution

class Pattern
{
    public static void main(String arr[])
    {
        int a,b;
        for(a=1;a<=5;a++)
        {
            for(b=1;b<=a;b++)
            {
                System.out.print(b);
            }
            System.out.println();
        }
    }
}
Output


Write a Java program to print Following Pattern:

Solution

class Pattern
{
    public static void main(String arr[])
    {
        int a,b;
        for(a=1;a<=5;a++)
        {
            for(b=4;b>=a;b--)
            {
                System.out.print(" ");
            }
            for(b=1;b<=a;b++)
            {
                System.out.print(b);
            }
            System.out.println();
        }
    }
}
Output


Write a Java program to print Following Pattern:

Solution

class Pattern
{
    public static void main(String arr[])
    {
        int a,b;
        for(a=1;a<=5;a++)
        {
            for(b=4;b>=a;b--)
            {
                System.out.print(" ");
            }
            for(b=1;b<=a;b++)
            {
                System.out.print("*");
            }
            System.out.println();
        }
    }
}
Output


Write a Java program to print Following Pattern:

Solution

class Pattern
{
    public static void main(String arr[])
    {
        int a,b;
        for(a=5;a>=1;a--)
        {
            for(b=4;b>=a;b--)
            {
                System.out.print(" ");
            }
            for(b=1;b<=a;b++)
            {
                System.out.print("*");
            }
            System.out.println();
        }
    }
}
Output


CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Website development Company in Allahabad