Java Pattern Program

1.Display the pattern


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

import java.util.*;
class Pattern
{
public static void main(String args[])
{
for(int i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print("*");
}
System.out.println();
}
}//end of main
}//end of class
OUTPUT:
*
**
***
****
*****

2.Display the pattern

11111
2222
333
44
5
class PP
{
public static void main(String args[])
{
for(int i=1;i<=5;i++)
{
for(int j=5;j>=i;j--)
{
System.out.print(i);
}
System.out.println();
}
}
}
OUTPUT:
11111
2222
333
44
5

3.Display the pattern

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

OUTPUT:
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

4.Display the pattern

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


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

5.Display the pattern

      1
     2 2
    3 3 3
   4 4 4 4
  5 5 5 5 5 

class MM
{
public static void main(String a[])
{
for(int i=1;i<=5;i++)
{
for(int k=4;k>=i;k--)
{
System.out.print(" ");
}
for(int j=1;j<=i;j++)
{
System.out.print(i+" ");
}
System.out.print("\n");
}
}
}
OUTPUT:
      1
     2 2
    3 3 3
   4 4 4 4
  5 5 5 5 5 

Translate »