In this tutorial, we will go through alphabet pattern programs in java programming. Before that, you may go through the following topic in java.
Half Repeated Character 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();
for (i = 0; i <= rows; i++)
{
int alphabet = 65;
for (j = 0; j < i; j++)
System.out.print(" ");
for (k = i; k <= rows; k++)
System.out.print((char)(alphabet + k));
System.out.println();
}
for (i = rows; i >= 0; i--)
{
int alphabet = 65;
for (j = 0; j < i; j++)
System.out.print(" ");
for (k = i; k <= rows; k++)
System.out.print((char)(alphabet + k));
System.out.println();
}
}
}
Output:
Enter the no. of rows: 5
ABCDEF
BCDEF
CDEF
DEF
EF
F
F
EF
DEF
CDEF
BCDEF
ABCDEF
