Java Program to Print Inverted Right-Angled Triangle with Row wise Increasing Character Pattern

Program to Print Inverted Right-Angled Triangle with Row wise Increasing Character Pattern

In this article we are going to see how to print the Inverted Right Angled with row wise Increasing Character program.

Example-1

When row value=4

ABCD
ABC
AB
A
Example-2:

When row value=5

ABCDE
ABCD
ABC
AB
A

Now, let’s see the actual program to print.

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 handel column value 
         for(col=1;col<=row_count-row+1;col++)
             // printing the result by column wise 
             // according to its ASCII value .
             System.out.print((char)(col+64));
         System.out.println("");
     }
    }
}
Output:

Enter rows : 5

ABCDE
ABCD
ABC
AB
A

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=1;col<=row_count-row+1;col++)
             printf("%c",(char)(col+64));
        printf("\n");
     }
   return 0;
}
Output:

Enter rows : 5

ABCDE
ABCD
ABC
AB
A

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=1;col<=row_count-row+1;col++)
            cout << (char)(col+64);
         cout << "\n";
     }
    return 0;
}
Output:

Enter rows : 5

ABCDE
ABCD
ABC
AB
A

Related Java Star Pattern Programs: