Java Program for Triangular Patterns of Alphabets



Java Program for Triangular Patterns of Alphabets :

Sample Code

import java.util.*;

public class alphtriangle 
{
  public static void main(String[] args) 
  {
    int i, j, n;
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter the no of lines ");
    n = sc.nextInt();
    for (i = 1; i <= n; i++) 
    {
      for (j = 1; j <= n - i; j++)
        System.out.print("  ");
      for (j = i; j > 0; j--)
        System.out.printf(" %c", (char)(j + 64));
      for (j = 2; j <= i; j++)
        System.out.printf(" %c", (char)(j + 64));

      System.out.println();
    }
  }
}

Output

Enter the no of lines 5
             A
         B A B
     C B A B C
  D C B A B C D
E D C B A B C D E

Related Searches to Java Program for Triangular Patterns of Alphabets