In this tutorial, we will go through different alphabet patterns in java. Before that, you may go through the following topic in java.
Both of the programs below take the user input for the number of rows to be printed for the alphabet pattern in java for the diamond shape.
Alphabet diamond pattern in java
import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
int rows, i, j, k;
Scanner sc = new Scanner(System.in);
System.out.print("Enter the no. of rows: ");
rows = sc.nextInt();
System.out.print("Diamond Shape Pattern: \n\n");
for (i = 0; i <= rows; i++)
{
int ch = 65;
for (j = rows; j >= i; j--)
{
System.out.print(" ");
}
for (k = 0; k <= i; k++)
{
System.out.print((char)(ch + k) + " ");
}
System.out.println();
}
for (i = 0; i <= rows; i++)
{
int ch = 65;
for (j = -1; j <= i; j++)
{
System.out.print(" ");
}
for (k = 0; k <= (rows - 1) - i; k++)
{
System.out.print((char)(ch + k) + " ");
}
System.out.println();
}
}
}
Output:

Hollow Diamond Alphabet Pattern in java
import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
int rows, i, j;
int ch = 65;
Scanner sc = new Scanner(System.in);
System.out.print("Enter the no. of rows: ");
rows = sc.nextInt();
System.out.print("Diamond Shape Pattern: \n\n");
//Upper part of diamond
for (i = 1; i <= rows; i++)
{
for (j = rows; j > i; j--)
System.out.print(" ");
System.out.print((char) ch++);
for (j = 1; j < (i - 1) *2; j++)
System.out.print(" ");
if (i == 1)
System.out.print("\n");
else
System.out.print((char) ch++ + "\n");
}
//lower part of diamond
ch = 65;
for (i = rows - 1; i >= 1; i--)
{
for (j = rows; j > i; j--)
System.out.print(" ");
System.out.print((char) ch++);
for (j = 1; j < (i - 1) *2; j++)
System.out.print(" ");
if (i == 1)
System.out.print("\n");
else
System.out.print((char) ch++ + "\n");
}
}
}
Output:

