Alphabet L pattern in java

L pattern
Steps to do this:-

1. take 3 integers i,j,n ( i and j is for loop and n is for user input length )

2. take a length from user

3. start the i loop from (i=1;i<=n;i++) start the j loop inside i loop and from (j=1;j<=n;j++) now check 
if(j==1||i==n)
{
print "*"
}
else
{
print " "
}
close the j loop and print a new line inside i loop

Explanation:-
when if (j==1) it will print the 1st coloumn
*
*
*
*
*
when we check if(i==n) it will print the last row





* * * * * *

and the end of the loop it will print L 

4.save and run

The Source Code

import  java.util.Scanner;
class  lpattern
{
    public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        int i,j,n;
        System.out.println("enter the length");
        n= s.nextInt();
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=n;j++)
            {
                if(i==n||j==1)
                {
                    System.out.print("*");
                }
                else
                {
                    System.out.print(" ");
                }
            }
            System.out.println();
        }
    }
}

OUTPUT 

Watch My Video

Comments

Popular Posts