Patterns Printing

Patterns Printing:


1. 11111
    2222
    333
    44
    5


class P1
{
         public static void main ( String args[] )
         {
                  for(int x=1; x<=5; x++)
                  {
                           for(int y=x; y<=5; y++)
                           {
                                    System.out.print (x) ;
                           }
                           System.out.println();
                  }
         }
}

2. 66
    777
    8888
    99999


class P2
{
         public static void main ( String args[] )
        {
                for(int x=6; x<=9; x++)
                {
                        for(int y=5; y<=x; y++)
                        {
                                System.out.print (x);
                        }
                        System.out.println();
                }
        }
}


3.     1
      12
    123
  1234
12345
  1234
    123
      12
        1

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


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


class P4
{
         public static void main ( String args[] )
        {
                for(int x=1; x<=5; x++)
                {
                        for(int y=x; y<=4; y++)
                        {
                                System.out.print (" ");
                        }
                        for(int y=1; y<=x; y++)
                        {
                                System.out.print (y + " ");
                        }
                        System.out.println();
                }
        }
}


5. 50 45 40 35
    30 25 20
    15 10
    5 

class P5
{
         public static void main ( String args[] )
        {
                int n = 50;
                for(int x=4; x>=1; x--)
                {
                        for(int y=1; y<=x; y++)
                        {
                                System.out.print (n + " ");
                                n- = 5;
                        }
                        System.out.println();
                }
        }
}

6.1 2 3 4 5
   2 2 3 4 5
   3 3 3 4 5
   4 4 4 4 5
   5 5 5 5 5 

class P6
{
        public static void main ( String args[] )
        {
              for(int x=1; x<=5; x++)
              {
                     for(int y=1; y<=5; y++)
                     {
                            System.out.print ((x>y?x:y)+ " ");
                     }
                     System.out.println();
              }
       }
}

7.* * * * * * *
   * * *    * * *
   * *          * *
   *                *
   * *          * *
   * * *    * * *
   * * * * * * *  


class P7
{
       public static void main ( String args[] )
       {
              for(int x=1; x<=7; x++)
              {
                     for(int y=1; y<=7; y++)
                     {
                            if ( x+y<=5 || x-y>=3 || y-x>=3 || x+y>=11)
                            {
                                   System.out.print ("* ");
                            }
                            else
                            {
                                   System.out.print (" ");
                            }
                     }
                     System.out.println();
              }
       }
}


8.1
   23
   456
   78910
   1112131415

class P8
{
        public static void main(String args[])
        {
                int c=1;
                for(int x=1;x<=5;x++)
                {
                        for(int y=1;y<=x;y++)
                        {
                                System.out.print(c );
                                c++;
                        }
                        System.out.println();
                }
        }
}

Post a Comment

0 Comments