- To print half triangle pattern using alphabet
User Input: 3
Output:
A A B A B 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;
rows=userInput.nextInt();
for(int i=1; i<=rows; i++) {
c='A';
for(int j=1; j<=i; j++) {
System.out.print((c++) +" ");
}
System.out.print("\n");
}
}
}
Enter number of rows : 4 A A B A B C A B C DProgram
Main logic :
for(int i=1; i<=rows; i++) { //rows : number of rows to print
c='A';
for(int j=1; j<=i; j++) {
System.out.print((c++) +" ");
}
System.out.print("\n");
}
You can print the same pattern in small alphabets, just set c='a'
Coming Soon !
QuickPractice isn’t the thing you do once you’re good. It’s the thing you do that makes you good.