Java program for the pattern of 'J' | Patterns in JAVA | JAVA POINT

Write a java program for the following pattern of 'J' .



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


PROGRAM :


import java.util.*;

class J

{

     public static void main(String[] args) 

     {

         int i,j,k,r,n;

         System.out.println("Enter the length : ");

         

         do{  

           Scanner sc=new Scanner(System.in);

           r=sc.nextInt(); 

           if(r<=1)

           {

           System.out.println("Enter the value Greater than 1");

           } 

           }while (r<=1);

        

          n = (r/2);    

           for (i=0;i<r;i++)

           {

                    if(i<n)

                    {

                      for (k=0;k<n+1;k++)

              {    

            System.out.print(" ");

              }

                  System.out.println("*");

                    }

                    else 

                    {

                      System.out.print("*");

              for (k=0;k<n;k++)

              {    

            System.out.print(" ");

              }

                  System.out.println("*");

                    }

           }

           for (j=0;j<n+2;j++)

       {    

           System.out.print("*");

       }

     }        

  }


/* Output :

Enter the length : 8


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

*/