Java Program to Print Square with Row wise Repeated with Decreasing Order Character Pattern

Printing Square with Row wise Repeated with Decreasing Order Character Pattern

In the previous article, we have discussed Java Program to Print Square with Row wise Repeated with Increasing Order Character Pattern

In this program we are going to see how to print square with row wise repeated with decreasing character pattern.

Example-1

When row value=5

EDCBA
EDCBA
EDCBA
EDCBA
EDCBA
Example-2:

When row value=9

IHGFEDCBA
IHGFEDCBA
IHGFEDCBA
IHGFEDCBA
IHGFEDCBA
IHGFEDCBA
IHGFEDCBA
IHGFEDCBA
IHGFEDCBA

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

The best and excellent way to learn a java programming language is by practicing Simple Java Program Examples as it includes basic to advanced levels of concepts.

Approach:

  • Enter total row and store it in an integer variable row_count.
  • Take one outer for loop to iterate the rows,
  • Inside the for loop, take one inner loop iterate the columns.
  • After each iteration print a new line.

Java Code to Print Square with Row wise Repeated with Decreasing Order Character Pattern

import java.util.Scanner;
class Main
{
public static void main(String[] args)  
{  
    Scanner scan = new Scanner(System.in);

    //Taking total rows as input from the user
    System.out.print("Rows : ");
    int row_count = scan.nextInt();

    int row,col;
    // Ascii value if 'A'
    int asciiAlpha = 65;

    for (row = 0; row < row_count; row++)
    {
        // Inner loop to print character
        for (col = row_count - 1; col >= 0; col--)
        {
            System.out.print((char)(col + asciiAlpha));
        }
        // Prints a newline
        System.out.println();
    }
}  
}
Output:

Rows : 9

IHGFEDCBA
IHGFEDCBA
IHGFEDCBA
IHGFEDCBA
IHGFEDCBA
IHGFEDCBA
IHGFEDCBA
IHGFEDCBA
IHGFEDCBA

C Code to Print Square with Row wise Repeated with Decreasing Order Character Pattern

#include <stdio.h>
#include <string.h>

int main()
{
    //Taking total rows as input from the user
    printf("Rows : ");
    int row_count;
    scanf("%d", &row_count);

    int row, col;

    // Ascii value if 'A'
    int asciiAlpha = 65;

    for (row = 0; row < row_count; row++)
    {
        // Inner loop to print character
        for (col = row_count - 1; col >= 0; col--)        {
            printf("%c", (col + asciiAlpha));
        }

        // Prints a newline
        printf("\n");
    }
    return 0;
}

Output:

Rows : 9

IHGFEDCBA
IHGFEDCBA
IHGFEDCBA
IHGFEDCBA
IHGFEDCBA
IHGFEDCBA
IHGFEDCBA
IHGFEDCBA
IHGFEDCBA

C++ Code to Print Square with Row wise Repeated with Decreasing Order Character Pattern

#include <iostream>
#include <cstring>
#include <string.h>
using namespace std;
int main(int argc, char const *argv[])
{
    //Taking total rows as input from the user
    cout << "Rows : ";
    int row_count;
    cin >> row_count;

    int row, col;

    // Ascii value if 'A'
    int asciiAlpha = 65;

    // Outer Loop
    for (row = 0; row < row_count; row++)
    {
        // Inner loop to print character
        for (col = row_count - 1; col >= 0; col--)
        {
            cout << (char)(col + asciiAlpha);
        }

        // Prints a newline
        cout << endl;
    }
    return 0;
}

Output:

Rows : 9

IHGFEDCBA
IHGFEDCBA
IHGFEDCBA
IHGFEDCBA
IHGFEDCBA
IHGFEDCBA
IHGFEDCBA
IHGFEDCBA
IHGFEDCBA

Are you seeking professional help for coding in the Java programming language? The tutorial of Java Programming Examples for beginners and experts will strongly improve your coding skills then you can program for any logic in Java.

Related Java Character Pattern Programs: