Java Program to Print Inverted Right-Angled Triangle with Repeated Character (Increasing order) Pattern

Program to Print Inverted Right-Angled Triangle with Repeated Character (Increasing order) Pattern

In this article we are going to see how to print the Inverted Right Angle with Repeated Increasing Character program.

Example-1

When row value=4

AAAA
BBB
CC
D
Example-2:

When row value=5

AAAAA
BBBB
CCC
DD
E

Now, let’s see the actual program.

Approach:

  • Enter total row and store it in an integer variable row_count.
  • Take first for loop to print all rows.
  • Take second/inner for loop to print column values.
  • Continue  printing the character  according to the iteration.

JAVA Code:

import java.util.*;
public class Main 
{    
    public static void main(String args[])   
    {   
    // taking variable for loop iteration and row .
    int row_count,row,col ;
    //creating object 
    Scanner s = new Scanner(System.in);
    // entering the number of row
    System.out.print("Enter rows : ");
    row_count = s.nextInt();	
    // FOR LOOP To HANDLE THE ROW VALUE
    for(row=1;row<=row_count;row++)
     {
         // FOR LOOP TO PRINT THE COLUMN VALUE
         for(col=row;col<=row_count;col++)
         {
             // FOR EACH COLUMN WE ARE PRINTING THE 
             // CHARACTER ACCORDINT TO IT ASCII VALE .
             System.out.print((char)(row+64));
         } 
         System.out.println("");
     }
    }
}
Output:

Enter rows : 5
/
AAAAA
BBBB
CCC
DD
E

C Code:

#include <stdio.h>
int main() 
{
   int row_count,row,col ;
   printf("Enter rows: ");
   scanf("%d", &row_count);
   for(row=1;row<=row_count;row++)
     {
        for(col=row;col<=row_count;col++)
           printf("%c",(char)(row+64));
        printf("\n");
     }
   return 0;
}

Output:

Enter rows : 5

AAAAA
BBBB
CCC
DD
E

C++ Code:

#include <iostream>
using namespace std;
int main()
{
   int row_count,row,col ;
   cout << "Enter  rows: ";
   cin >> row_count;
    for(row=1;row<=row_count;row++)
     {
         for(col=row;col<=row_count;col++)
             cout << (char)(row+64);
         cout << "\n";
     }
    return 0;
}

Output:

Enter rows : 5

AAAAA
BBBB
CCC
DD
E

Related Java Star Pattern Programs: