Java Program for Character triangle shape.





package demo;
import java.util.Scanner;
public class CharacterTriangle
{
 public static void main(String[] args) 
 {
  int n = 1;
  char r, c, ch;
  System.out.println("Enter seed character : ");
  Scanner sc = new Scanner(System.in);
  ch = sc.next().charAt(0);
  if (ch >= 'a' && ch <= 'z') {
   ch = (char)(ch - 32);
  }
  for (r = 'A'; r <= ch; r++, n++) {
   for (c = 'A'; c <= ch - n + 1; c++) {
    System.out.print(c);
   }
   System.out.println();
  }
 }
}

OUTPUT:

Enter seed character : 
e
ABCDE
ABCD
ABC
AB
A

BUILD SUCCESSFUL (total time: 9 seconds)


No comments:

Post a Comment