Character triangle pyramid program in Java



import java.util.Scanner;
public class CharacterTrianglePyramid {
 public static void main(String[] args) 
 {
  char ch;
  int sp;
  Scanner sc = new Scanner(System.in);
  System.out.print("Enter last character of triangle : ");
  ch = sc.next().charAt(0);
  if (ch >= 'a' && ch <= 'z') {
   ch = (char)(ch - 32);
  }
  System.out.println();
  for (char r = 'A'; r <= ch; ch--) {
   for (char c = ch; c >= r; c--) {
    System.out.print(c);
   }
   System.out.println();
  }
 }
}

Output:

Enter last character of triangle : e

EDCBA
DCBA
CBA
BA
A

BUILD SUCCESSFUL (total time: 5 seconds)


Note: Hello friends, If you have any better solution for this programs then please comment below, I will add your comment as a solution for this programs.

Thanks for visiting my blog.