import java.util.Scanner;
public class SquareCharacterTriangle
{
 public static void main(String[] args) {
  char ch;
  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; r++) {
   for (char c = r; c >= ‘A’; c–) {
    System.out.print(c);
   }
   System.out.println();
  }
  for (char r=”A”;
   ‘A’ <= ch; ch–, r++) {
   for (char c = (char)(ch – 1); c >= ‘A’; c–) {
    System.out.print(c);
   }
   System.out.println();
  }
 }
}

Output:

Enter last character of triangle : d

A
BA
CBA
DCBA
CBA
BA
A

BUILD SUCCESSFUL (total time: 4 seconds)

LEAVE A REPLY

Please enter your comment!
Please enter your name here