Pattern Type Three Program in Java

Pattern Type Three Program in Java
Pattern Type Three Program in Java

public class Pattern21
{
    public static void main(String[] args)
    {
        for (int i = 1; i <= 5; i++)
        {
            for (int j = 5 - i; j >= 1; j--)
            {
                System.out.print(" ");
            }
            for (int j = 1; j <= i; j++)
            {
                System.out.print("*");
            }
            System.out.println();
        }
    }
}

Output:

    *
   **
  ***
 ****
*****


public class Pattern22
{
    public static void main(String[] args)
    {
        for (int i = 1; i <= 5; i++)
        {
            for (int j = 5 - i; j >= 1; j--)
            {
                System.out.print(" ");
            }
            for (int j = 1; j <= i; j++)
            {
                System.out.print(i);
            }
            System.out.println();
        }
    }
}

Output:

    1
   22
  333
 4444
55555


public class Pattern23
{
    public static void main(String[] args)
    {
        for (int i = 1; i <= 5; i++)
        {
            for (int j = 5 - i; j >= 1; j--)
            {
                System.out.print(" ");
            }
            for (int j = 1; j <= i; j++)
            {
                System.out.print(j);
            }
            System.out.println();
        }
    }
}

Output:

    1
   12
  123
 1234
12345


public class Pattern24
{
    public static void main(String[] args)
    {
        for (int i = 1; i <= 5; i++)
        {
            for (int j = 5 - i; j >= 1; j--)
            {
                System.out.print(" ");
            }
            for (int j = 1; j <= i; j++)
            {
                System.out.print(i % 2);
            }
            System.out.println();
        }
    }
}

Output:

    1
   00
  111
 0000
11111


public class Pattern25
{
    public static void main(String[] args)
    {
        for (int i = 1; i <= 5; i++)
        {
            for (int j = 5 - i; j >= 1; j--)
            {
                System.out.print(" ");
            }
            for (int j = 1; j <= i; j++)
            {
                System.out.print(j % 2);
            }
            System.out.println();
        }
    }
}

Output:

    1
   10
  101
 1010
10101


public class Pattern26
{
    public static void main(String[] args)
    {
        for (int i = 1; i <= 5; i++)
        {
            for (int j = 5 - i; j >= 1; j--)
            {
                System.out.print(" ");
            }
            for (int j = 1; j <= i; j++)
            {
                System.out.print((j+1) % 2);
            }
            System.out.println();
        }
    }
}

Output:

    0
   01
  010
 0101
01010


public class Pattern28
{
    public static void main(String[] args)
    {
        int k;
        for (int i = 1; i <= 5; i++)
        {
            for (int j = 5 - i; j >= 1; j--)
            {
                System.out.print(" ");
            }
            k = i;
            for (int j = 1; j <= i; j++)
            {
                System.out.print(k);
                k++;
            }
            System.out.println();
        }
    }
}

Output:

    1
   23
  345
 4567
56789 


public class Pattern29
{
    public static void main(String[] args)
    {
        int k;
        for (int i = 1; i <= 5; i++)
        {
            for (int j = 5 - i; j >= 1; j--)
            {
                System.out.print(" ");
            }
            k = i;
            for (int j = 1; j <= i; j++)
            {
                System.out.print(k % 2);
                k++;
            }
            System.out.println();
        }
    }
}

Output:

    1
   01
  101
 0101
10101


public class Pattern30
{
    public static void main(String[] args)
    {
        for (int i = 1; i <= 5; i++)
        {
            for (int j = 5 - i; j >= 1; j--)
            {
                System.out.print(" ");
            }
            for (int j = 1; j <= i; j++)
            {
                if (i % 2 == 0)
                {
                    System.out.print("#");
                }
                else
                {
                    System.out.print("*");
                }
            }
            System.out.println();
        }
    }
}

Output:

    *
   ##
  ***
 ####
***** 
b. tech. bca icse java java tutorials learn java mca programs
Recent Posts