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

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

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

Example-1

When row value=4

ABCD
BCD
CD
D

Example-2:

When row value=5

ABCDE
BCDE
CDE
DE
E

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

Approach:

  1. Enter total number of rows and store it in an integer variable row_count.
  2. Take first for loop to print all rows.
  3. Take second/inner for loop to print column values.
  4. 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 scanner class 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 ACCORDING TO IT ASCII VALUE .
                 System.out.print((char)(col+64));
             System.out.println("");
         }    
        
    }   
    
}



Output:

Enter rows : 5

ABCDE
BCDE
CDE
DE
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)(col+64));
          printf("\n");
     }
   return 0;
}
Output:

Enter rows : 5

ABCDE
BCDE
CDE
DE
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)(col+64);
         cout << "\n";
     }
    return 0; 
}
Output:

Enter rows : 5

ABCDE
BCDE
CDE
DE
E

Related Java Star Pattern Programs: