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

 

Java Program for I



Ques - Write a java program for the following pattern of 'I' .


*****

   *

   *

   *

   *

*****



PROGRAM :


import java.util.Scanner;

class I

 {

     public static void main(String []args)

     {

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

         Scanner sc=new Scanner(System.in);

         int i, j, n;

         int r=sc.nextInt();


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

         {

             for(j=0;j<5;j++)

             {

                 if((i==0)||(i==(r-1)))

                 {

                     System.out.print("*");

                 }    

                 else if(j==2)

                 {

                     System.out.print("*");

                 }    

                 else

                 {

                     System.out.print(" ");

                 }

             }

             System.out.println();

         }

        }

 }


/* Output :

 

Enter the length : 6


*****

   *

   *

   *

   *

*****

 

*/