Java Program:

- To print half triangle pattern using alphabet

Example:

User Input: 3

Output:

A
B B
C C C
import java.util.Scanner;

public class Pattern {

  public static void main(String[] args) {
    Scanner userInput = new Scanner(System.in);
    System.out.print("Enter number of rows : ");

    int rows;
    char c='A';
    rows=userInput.nextInt();
    for(int i=1; i<=rows; i++) {
      for(int j=1; j<=i; j++) {
        System.out.print(c +" ");
      }
      c++;
      System.out.print("\n");
    }

  }
}

Output:

  Enter number of rows : 4
  A
  B B
  C C C
  D D D D
Program
pattern

Main logic :

c='A';
for(int i=1; i<=rows; i++) {  //rows : number of rows to print
  for(int j=1; j<=i; j++) {
    System.out.print(c +" ");
  }
  c++;
  System.out.print("\n");
}

You can print the same pattern in small alphabets, just set c='a'

Concept

Coming Soon !

Quick
Tutorial

Quote

Learn from yesterday, live for today, hope for tomorrow. The important thing is not to stop questioning.