I J K and L character pattern programs in Java

A to Z character pattern programs in java part 3

I J K and L character pattern programs in Java

In this series of tutorial, we will study how to print character pattern programs in java. In this post, we will see how to create pattern I, J, K and L in Java.

1.  Character Pattern I in Java

In this program we study how to display character pattern I using Java Programming language.

import java.util.*;
class I
{
  public static void main(String[] args) 
  {
    Scanner scan =new Scanner(System.in);
    System.out.println("Enter the value of n");
    int n=scan.nextInt();
    for(int i=0;i<n;i++)
    {
      for(int j=0;j<n;j++)
      {
        if(i==0||i==n-1||j==(n-1)/2)
        {
          System.out.print("*");
        }
        else
        {
          System.out.print(" ");
        }

      }
      System.out.println();
    }
  }
}

Output of pattern I in java

Enter the value of n
8
********
*
*
*
*
*
*
********

2.  Character Pattern J in Java

In this program we learn how to display character pattern J using Java Programming language.

import java.util.*;
class J
{
  public static void main(String[] args) 
  {
    Scanner scan =new Scanner(System.in);
    System.out.println("Enter the value of n");
    int n=scan.nextInt();
    for(int i=0;i<n;i++)
    {
      for(int j=0;j<n;j++)
      {
        if(i==0&&j>n/4||j==3*(n/4)||i==n-1&&j<3*(n/4)&&j!=0&&i>n/2)
        {
          System.out.print("*");
        }
        else
        {
          System.out.print(" ");
        }

      }
      System.out.println();
    }
  }
}

Output of pattern J in java

Enter the value of n
8
*****
*
*
*
*
*
*
******

3.  Character Pattern K in Java

In this program we study how to print character pattern K using Java Programming language.

import java.util.*;
class K
{
  public static void main(String[] args) 
  {
    Scanner scan =new Scanner(System.in);
    System.out.println("enter the value of n");
    int n=scan.nextInt();
    for(int i=0;i<n;i++)
    {
      for(int j=0;j<n;j++)
      {
        if(i>=0&&j==0||i==j&&j>=n/2||i+j==n-1&&i<3*(n/4))
        {
          System.out.print("*");
        }
        else
        {
          System.out.print(" ");
        }
      }
      System.out.println();
    }
  }
}

Output of pattern K in java

Enter the value of n
8
* *
* *
* *
* *
* **
* * *
* *
* *

4.  Character Pattern L in Java

In this program we learn how to print character pattern L using Java Programming language.

import java.util.*;
class L
{
  public static void main(String[] args) 
  {
    Scanner scan =new Scanner(System.in);
    System.out.println("enter the value of n");
    int n=scan.nextInt();
    for(int i=0;i<n;i++)
    {
      for(int j=0;j<n;j++)
      {
        if(i>=0&&i<n-1&&j==0||i==n-1&&j>0)
        {
          System.out.print("*");
        }
        else
        {
          System.out.print(" ");
        }
      }
      System.out.println();
    }
  }
}

Output of pattern L in java

Enter the value of n
8
*
*
*
*
*
*
*
*******

These series of articles deals with how to display character and alphabet pattern programs in java, displaying different diamond pattern programs in java, printing number pattern programs in java, alphabet pattern programs in java, pattern programs in java with explanation, printing string pattern programs in java, diamond number pattern programs in java, square pattern programs in java. These are the commonly asked pattern programs in many campus and off campus placement interviews.

READ  Python program to find the largest smallest average of a list

If you find anything incorrect please contact us at click hereFor regular updates and suggestions please like the facebook page