Java Program to Print Right Angled Triangle with Repeating Character (Decreasing Order) Pattern

Program to Print Right Angled Triangle with Repeating Character Pattern (Decreasing Order)

In this program we are going to see how to print the right angled triangle with repeating character pattern in decreasing order.

Example-1

When character=h 
and row value=3

h
g g
f  f  f
Example-2:

When character=Z 
and row value=5

Z
Y Y
X X X
W W W W
V  V  V  V  V

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

Interested in programming and want to excel in it by choosing the short ways. Then, practicing with the available Java Program list is mandatory.

Approach:

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

JAVA CODE:

import java.util.Scanner;
class Main
{
    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        //Taking character to be printed 
        // as input from the user
        System.out.print("First Character : ");
        char c = scan.next().charAt(0);
    
        //Taking number of rows as input from the user
        System.out.print("Rows : ");
        int row_count = scan.nextInt();
    
        int row, col;
        //Converting the character to its ascii value
        int asciiValue = (int) c;
    
        //Checks whether the character is a letter or not
        if(asciiValue>=65&&asciiValue<=122)
        {
            //Outer loop to iterate rows
            for(row = 0; row<row_count; row++)
            {
                //Inner loop to iterate columns
                for(col = 0; col<row+1; col++)
                {
                    System.out.print(c+" ");
                }
                //Decrementing the character
                    c--;
                //Prints a newline
                System.out.println();
            }
        }
    }
}
Output:

Character : Z
Rows : 5

Z
Y  Y
X  X  X
W W W W
V  V  V  V  V

C CODE:

#include <stdio.h>

int main()
{
    //Taking character to be printed as input from the user
    printf("Character : ");
    char c;
    scanf("%c", &c);

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

    int row, col;
    //Converting the character to its ascii value
    int asciiValue = (int)c;

    //Checks whether the character is a letter or not
    if (asciiValue >= 65 && asciiValue <= 122)
    {
        //Outer loop to iterate rows
        for (row = 0; row < row_count; row++)
        {
            //Inner loop to iterate columns
            for (col = 0; col < row + 1; col++)
            {
                printf("%c ", c);
            }
            //Decrementing the character
            c--;
            //Prints a newline
            printf("\n");
        }
    }
    return 0;
}

Output:

Character : Z
Rows : 5

Z
Y  Y
X  X  X
W W W W
V  V  V  V  V

C++ CODE:

#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    //Taking character to be printed as input from the user
    cout << "Character : ";
    char c;
    cin >> c;

    //Taking number of rows as input from the user
    cout << "Rows : ";
    int row_count;
    cin >> row_count;

    int row, col;
    //Converting the character to its ascii value
    int asciiValue = (int)c;

    //Checks whether the character is a letter or not
    if (asciiValue >= 65 && asciiValue <= 122)
    {
        //Outer loop to iterate rows
        for (row = 0; row < row_count; row++)
        {
            //Inner loop to iterate columns
            for (col = 0; col < row + 1; col++)
            {
                cout << c << " ";
            }
            //Decrementing the character
            c--;
            //Prints a newline
            cout << endl;
        }
    }
    return 0;
}

Output:

Character : Z
Rows : 5

Z
Y  Y
X  X  X
W W W W
V  V  V  V  V

Related Java Star Pattern Programs:

Java Program to Print Right Angled Triangle with Repeating Character (Increasing Order) Pattern

Program to Print Right Angled Triangle with Repeating Character Pattern (Increasing Order)

In this program we are going to see how to print the right angled triangle with repeating character pattern in increasing order.

Example-1

When character=h 
and row value=3

h
i i
j j j
Example-2:

When character=A 
and row value=5

A
B B
C C C
D D D D
E  E  E  E E

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

Practice Java programming from home without using any fancy software just by tapping on this Simple Java Programs for Beginners tutorial.

Approach:

  • Enter the character and store it in a variable c.
  • Then enter total row and store it in an integer variable row_count.
  • Take one outer for loop to iterate the rows.
  • Take one inner loop to iterate the columns and print the character.
  • After each iteration print a newline.

JAVA CODE:

import java.util.Scanner;
class Main
{
    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        //Taking character to be printed 
        //as input from the user
        System.out.print("First Character : ");
        char c = scan.next().charAt(0);
    
        //Taking number of rows as input from the user
        System.out.print("Rows : ");
        int row_count = scan.nextInt();
    
        int row, col;
        //Converting the character to its ascii value
        int asciiValue = (int) c;
    
        //Checks whether the character is a letter or not
        if(asciiValue>=65&&asciiValue<=122)
        {
            //Outer loop to iterate rows
            for(row = 0; row<row_count; row++)
            {
                //Inner loop to iterate columns
                for(col = 0; col<row+1; col++)
                {
                    System.out.print(c+" ");
                }
                //Incrementing the character
                    c++;
                //Prints a newline
                System.out.println();
            }
        }
    }
}

Output

Character : A
Rows : 5

A
B B
C C C
D D D D
E  E  E E E

C CODE:

#include <stdio.h>

int main()
{
    //Taking character to be printed as input from the user
    printf("Character : ");
    char c;
    scanf("%c", &c);

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

    int row, col;
    //Converting the character to its ascii value
    int asciiValue = (int)c;

    //Checks whether the character is a letter or not
    if (asciiValue >= 65 && asciiValue <= 122)
    {
        //Outer loop to iterate rows
        for (row = 0; row < row_count; row++)
        {
            //Inner loop to iterate columns
            for (col = 0; col < row + 1; col++)
            {
                printf("%c ", c);
            }
            //Incrementing the character
            c++;
            //Prints a newline
            printf("\n");
        }
    }
    return 0;
}

Output:

Character : A
Rows : 5

A
B B
C C C
D D D D
E  E  E E E

C++ CODE:

#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    //Taking character to be printed as input from the user
    cout << "Character : ";
    char c;
    cin >> c;

    //Taking number of rows as input from the user
    cout << "Rows : ";
    int row_count;
    cin >> row_count;

    int row, col;
    //Converting the character to its ascii value
    int asciiValue = (int)c;

    //Checks whether the character is a letter or not
    if (asciiValue >= 65 && asciiValue <= 122)
    {
        //Outer loop to iterate rows
        for (row = 0; row < row_count; row++)
        {
            //Inner loop to iterate columns
            for (col = 0; col < row + 1; col++)
            {
                cout << c << " ";
            }
            //Incrementing the character
            c++;
            //Prints a newline
            cout << endl;
        }
    }
    return 0;
}
Output:

Character : A
Rows : 5

A
B B
C C C
D D D D
E  E  E E E

Related Java Star Pattern Programs:

Java Program to Print Right Angled Triangle with Increasing Alternate Case Character Pattern

Program to Print Right Angled Triangle with Increasing Alternate Case Character Pattern

In this program we are going to see how to print the right angled triangle with increasing alternate case character pattern.

Example-1

When starting character=h 
and row value=3

h
I j
k L m
Example-2:

When starting character=a 
and row value=5

a
B c
d E f
G h I j
k L m N o

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

Don’t stop learning now. Get hold of all the important Java fundamentals with the Simple java program example guide and practice well.

Approach:

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

JAVA CODE:

import java.util.Scanner;
import java.lang.*;
class Main
{
    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        //Taking character to be printed as input from the user
        System.out.print("First Character : ");
        char c = scan.next().charAt(0);
    
        //Taking number of rows as input from the user
        System.out.print("Rows : ");
        int row_count = scan.nextInt();
    
        int row, col;
        //Converting the character to its ascii value
        int asciiValue = (int) c;
    
        //Checks whether the character is a letter or not
        if(asciiValue>=65&&asciiValue<=122)
        {
            //Outer loop to iterate rows
            for(row = 0; row<row_count; row++){
                //Inner loop to iterate columns
                for(col = 0; col<row+1; col++){
                    //Alternating the case in each iteration
                    if((row+col)%2==0)
                        System.out.print(Character.toLowerCase(c)+" ");
                    else
                        System.out.print(Character.toUpperCase(c)+" ");
                    //Incrementing the character
                    c++;
                }
                //Prints a newline
                System.out.println();
            }
        }
    }
}
Output

First Character : a
Rows : 5

a
B c
d E f
G h I j
k L m N o

C CODE:

#include <stdio.h>

int main()
{
    //Taking character to be printed as input from the user
    printf("First Character : ");
    char c;
    scanf("%c", &c);

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

    int row, col;
    //Converting the character to its ascii value
    int asciiValue = (int)c;

    //Checks whether the character is a letter or not
    if (asciiValue >= 65 && asciiValue <= 122)
    {
        //Outer loop to iterate rows
        for (row = 0; row < row_count; row++)
        {
            //Inner loop to iterate columns
            for (col = 0; col < row + 1; col++)
            {
                //Alternating the case in each iteration
                if ((row + col) % 2 == 0)
                    printf("%c ", tolower(c));
                else
                    printf("%c ", toupper(c));
                //Incrementing the character
                c++;
            }
            //Prints a newline
            printf("\n");
        }
    }
    return 0;
}
Output

First Character : a
Rows : 5

a
B c
d E f
G h I j
k L m N o

C++ CODE:

#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    //Taking character to be printed as input from the user
    cout << "First Character : ";
    char c;
    cin >> c;

    //Taking number of rows as input from the user
    cout << "Rows : ";
    int row_count;
    cin >> row_count;

    int row, col;
    //Converting the character to its ascii value
    int asciiValue = (int)c;

    //Checks whether the character is a letter or not
    if (asciiValue >= 65 && asciiValue <= 122)
    {
        //Outer loop to iterate rows
        for (row = 0; row < row_count; row++)
        {
            //Inner loop to iterate columns
            for (col = 0; col < row + 1; col++)
            {
                //Alternating the case in each iteration
                if ((row + col) % 2 == 0)
                    cout << (char)tolower(c) << " ";
                else
                    cout << (char)toupper(c) << " ";
                //Incrementing the character
                c++;
            }
            //Prints a newline
            cout << endl;
        }
    }
    return 0;
}

Output:  First Character : a
Rows : 5

a
B c
d E f
G h I j
k L m N o

Related Java Star Pattern Programs:

Java Program to Print Equilateral Triangle Character Pattern

Program to Print Equilateral Triangle Character Pattern

In the previous article, we have discussed Java Program to Print Downward Triangle Character Pattern

In this program we are going to see how to print an equilateral triangle character pattern.

Example-1

When character=h 
and row value=3

   h
   i j
 k l m
Example-2:

When character=A 
and row value=5

      A
     B C
    D E F
   G H I J
 K L M N O

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

Access the Simple Java program for Interview examples with output from our page and impress your interviewer panel with your coding skills.

Approach:

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

Java Code to Print Equilateral Triangle Character Pattern

import java.util.Scanner;
class Main
    {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        //Taking character to be printed as input from the user
        System.out.print("Character : ");
        char c = scan.next().charAt(0);
    
        //Taking number of rows as input from the user
        System.out.print("Rows : ");
        int row_count = scan.nextInt();
    
        int row, col;
        //Converting the character to its ascii value
        int asciiValue = (int) c;
    
        //Checks whether the character is a letter or not
        if(asciiValue>=65&&asciiValue<=122)
        {
            
            //Outer loop to iterate rows
            for (row = 0; row < row_count; row++)
            {
                //Inner loop to print space
                for (col = row_count; col >row; col--)
                {
                    System.out.print(" ");
                    
                }
                //Inner loop to print character
                for(col = 0; col<=row; col++)
                {
                    System.out.print(c+" ");
                    c++;
                }
                //Prints a newline
                System.out.println();
            }
        }
    }
}

Output:

Character : A
Rows : 5

       A
     B C
    D E F
   G H  I  J
 K L M N O

C Code to Print Equilateral Triangle Character Pattern

#include <stdio.h>

int main()
{
    //Taking character to be printed as input from the user
    printf("Character : ");
    char c;
    scanf("%c", &c);

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

    int row, col;
    //Converting the character to its ascii value
    int asciiValue = (int)c;

    //Checks whether the character is a letter or not
    if (asciiValue >= 65 && asciiValue <= 122)
    {
        //Outer loop to iterate rows
        for (row = 0; row < row_count; row++)
        {
            //Inner loop to print space
            for (col = row_count; col > row; col--)
            {
                printf(" ");
            }
            //Inner loop to print character
            for (col = 0; col <= row; col++)
            {
                printf("%c ", c++);
            }
            //Prints a newline
            printf("\n");
        }
    }
    return 0;
}
Output:

Character : A
Rows : 5

       A
     B  C
   D  E  F
  G  H  I  J
 K L M N O

C++ Code to Print Equilateral Triangle Character Pattern

#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    //Taking character to be printed as input from the user
    cout << "Character : ";
    char c;
    cin >> c;

    //Taking number of rows as input from the user
    cout << "Rows : ";
    int row_count;
    cin >> row_count;

    int row, col;
    //Converting the character to its ascii value
    int asciiValue = (int)c;

    //Checks whether the character is a letter or not
    if (asciiValue >= 65 && asciiValue <= 122)
    {
        //Outer loop to iterate rows
        for (row = 0; row < row_count; row++)
        {
            //Inner loop to print space
            for (col = row_count; col > row; col--)
            {
                cout << " ";
            }
            //Inner loop to print characters
            for (col = 0; col <= row; col++)
            {
                cout << c++ << " ";
            }
            //Prints a newline
            cout << endl;
        }
    }
    return 0;
}

Output:

Character : A
Rows : 5

       A
     B  C
   D  E  F
  G  H  I  J
 K L M N O

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:

Java Program to Print Right Angled Triangle with Decreasing Character Pattern

Program to Print Right Angled Triangle with Decreasing Character Pattern

In this program we are going to see how to print the right angled triangle with decreasing character pattern.

Example-1

When character=h & row value=3

h
g f
e d c
Example-2:

When character=z & row value=5

Z
Y X
W V U
T S R Q
P O N M L

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

Don’t miss the chance of Java programs examples with output pdf free download as it is very essential for all beginners to experienced programmers for cracking the interviews.

Approach:

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

JAVA CODE:

import java.util.Scanner;
class Main
{
    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        //Taking character to be printed as 
        // input from the user
        System.out.print("Last Character : ");
        char c = scan.next().charAt(0);
    
        //Taking number of rows as input from the user
        System.out.print("Rows : ");
        int row_count = scan.nextInt();
    
        int row, col;
        //Converting the character to its ascii value
        int asciiValue = (int) c;
    
        //Checks whether the character is a letter or not
        if(asciiValue>=65&&asciiValue<=122)
        {
            //Outer loop to iterate rows
            for(row = 0; row<row_count; row++)
            {
                //Inner loop to iterate columns
                for(col = 0; col<row+1; col++)
                {
                    System.out.print(c+" ");
                    //Decrementing the character
                    c--;
                }
                //Prints a newline
                System.out.println();
            }
        }
    }
}
Output:

Last Character : Z
Rows : 5

Z 
Y X 
W V U
T S R Q 
P O N M L

C CODE:

#include <stdio.h>

int main()
{
    //Taking character to be printed as input from the user
    printf("Last Character : ");
    char c;
    scanf("%c", &c);

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

    int row, col;
    //Converting the character to its ascii value
    int asciiValue = (int)c;

    //Checks whether the character is a letter or not
    if (asciiValue >= 65 && asciiValue <= 122)
    {
        //Outer loop to iterate rows
        for (row = 0; row < row_count; row++)
        {
            //Inner loop to iterate columns
            for (col = 0; col < row + 1; col++)
            {
                printf("%c ", c);
                //Decrementing the character
                c--;
            }
            //Prints a newline
            printf("\n");
        }
    }
    return 0;
}
Output:

Last Character : Z
Rows : 5

Z 
Y X 
W V U
T S R Q 
P O N M L

C++ CODE:

#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    //Taking character to be printed as input from the user
    cout << "Last Character : ";
    char c;
    cin >> c;

    //Taking number of rows as input from the user
    cout << "Rows : ";
    int row_count;
    cin >> row_count;

    int row, col;
    //Converting the character to its ascii value
    int asciiValue = (int)c;

    //Checks whether the character is a letter or not
    if (asciiValue >= 65 && asciiValue <= 122)
    {
        //Outer loop to iterate rows
        for (row = 0; row < row_count; row++)
        {
            //Inner loop to iterate columns
            for (col = 0; col < row + 1; col++)
            {
                cout << c << " ";
                //Decrementing the character
                c--;
            }
            //Prints a newline
            cout << endl;
        }
    }
    return 0;
}

Output:

Last Character : Z
Rows : 5

Z 
Y X 
W V U
T S R Q 
P O N M L

Related Java Star Pattern Programs:

Java Program to Print Right Angled Triangle with Increasing Character Pattern

Program to Print Right Angled Triangle with Increasing Character Pattern

In this program we are going to see how to print the right angled triangle with increasing character pattern.

Example-1

When character=f & row value=3

f
g h
i   j  k
Example-2:

When character=a & row value=5

A
B C
D E F
G H I  J
K L M N O

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

If you are new to Java and want to learn the java coding skills too fast. Try practicing the core java programs with the help of the Java basic programs list available.

Approach:

  • Enter the character and store it in a variable c, then enter total row and store it in an integer variable row_count.
  • Take one outer for loop to iterate the rows.
  • Take one inner loop to iterate the columns and print the character.
  • After each iteration print a newline.

JAVA CODE:

import java.util.Scanner;

class Main
{
    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        //Taking character to be printed as 
        // input from the user
        System.out.print("First Character : ");
        char c = scan.next().charAt(0);
    
        //Taking number of rows as input from the user
        System.out.print("Rows : ");
        int row_count = scan.nextInt();
    
        int row, col;
        //Converting the character to its ascii value
        int asciiValue = (int) c;
    
        //Checks whether the character is a letter or not
        if(asciiValue>=65&&asciiValue<=122)
        {
            //Outer loop to iterate rows
            for(row = 0; row<row_count; row++)
            {
                //Inner loop to iterate columns
                for(col = 0; col<row+1; col++)
                {
                    System.out.print(c+" ");
                    //Incrementing the character
                    c++;
                }
                //Prints a newline
                System.out.println();
            }
        }
    }
}
Output:

First Character : A
Rows : 5

A
B C
D E F
G H I J
K L M N O

C CODE:

#include <stdio.h>

int main()
{
    //Taking character to be printed as input from the user
    printf("First Character : ");
    char c;
    scanf("%c", &c);

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

    int row, col;
    //Converting the character to its ascii value
    int asciiValue = (int)c;

    //Checks whether the character is a letter or not
    if (asciiValue >= 65 && asciiValue <= 122)
    {
        //Outer loop to iterate rows
        for (row = 0; row < row_count; row++)
        {
            //Inner loop to iterate columns
            for (col = 0; col < row + 1; col++)
            {
                printf("%c ", c);
                //Incrementing the character
                c++;
            }
            //Prints a newline
            printf("\n");
        }
    }
    return 0;
}

Output:

First Character : A
Rows : 5

A
B C
D E F
G H I J
K L M N O

C++ CODE:

#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    //Taking character to be printed as input from the user
    cout << "First Character : ";
    char c;
    cin >> c;

    //Taking number of rows as input from the user
    cout << "Rows : ";
    int row_count;
    cin >> row_count;

    int row, col;
    //Converting the character to its ascii value
    int asciiValue = (int)c;

    //Checks whether the character is a letter or not
    if (asciiValue >= 65 && asciiValue <= 122)
    {
        //Outer loop to iterate rows
        for (row = 0; row < row_count; row++)
        {
            //Inner loop to iterate columns
            for (col = 0; col < row + 1; col++)
            {
                cout << c << " ";
                //Incrementing the character
                c++;
            }
            //Prints a newline
            cout << endl;
        }
    }
    return 0;
}
Output:

First Character : A
Rows : 5

A
B C
D E F
G H I J
K L M N O

Related Java Star Pattern Programs:

Java Program to Print Downward Triangle Character Pattern

Program to Print Downward Triangle Character Pattern

In the previous article, we have discussed Java Program to Print Triangle with Repeated Character (Decreasing Order) Pattern

In this program we are going to see how to print downward triangle character pattern.

Example-1

When character=h 
and row value=3

   h i j
    h i
     h
Example-2:

When character=A 
and row value=5

  A B C D E
   A B C D
    A B C
     A B
      A

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

Interested in programming and want to excel in it by choosing the short ways. Then, practicing with the available Java Program list is mandatory.

Approach:

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

Java to Print Downward Triangle Character Pattern

import java.util.Scanner;
class Main
{
public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    //Taking character to be printed as input from the user
    System.out.print("Character : ");
    char c = scan.next().charAt(0);

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

    int row, col;
    //Converting the character to its ascii value
    int asciiValue = (int) c;

    //Checks whether the character is a letter or not
    if(asciiValue>=65&&asciiValue<=122)
    {
        
        //Outer loop to iterate rows
        for (row = 1; row <= row_count; row++)
        {
            //Inner loop to print space
            for (col = 0; col <=row; col++)
            {
                System.out.print(" ");
                
            }
            //Inner loop to print character
            for(col = 0; col<=row_count-row; col++)
            {
                System.out.print((char)(asciiValue+col)+" ");
            }
            //Prints a newline
            System.out.println();
        }
    }
}
}

Output:

Character : A
Rows : 5

A B C D E
  A B C D
   A B C
    A B
      A

C to Print Downward Triangle Character Pattern

#include <stdio.h>

int main()
{
    //Taking character to be printed as input from the user
    printf("Character : ");
    char c;
    scanf("%c", &c);

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

    int row, col;
    //Converting the character to its ascii value
    int asciiValue = (int)c;

    //Checks whether the character is a letter or not
    if (asciiValue >= 65 && asciiValue <= 122)
    {
        //Outer loop to iterate rows
        for (row = 1; row <= row_count; row++)
        {
            //Inner loop to print space
            for (col = 0; col <= row; col++)
            {
                printf(" ");
            }
            //Inner loop to print character
            for (col = 0; col <= row_count - row; col++)
            {
                printf("%c ", (char)(asciiValue + col));
            }
            //Prints a newline
            printf("\n");
        }
    }
    return 0;
}


Output:

Character : A
Rows : 5

A B C D E
  A B C D
   A B C
    A B
      A

C++ to Print Downward Triangle Character Pattern

#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    //Taking character to be printed as input from the user
    cout << "Character : ";
    char c;
    cin >> c;

    //Taking number of rows as input from the user
    cout << "Rows : ";
    int row_count;
    cin >> row_count;

    int row, col;
    //Converting the character to its ascii value
    int asciiValue = (int)c;

    //Checks whether the character is a letter or not
    if (asciiValue >= 65 && asciiValue <= 122)
    {
        //Outer loop to iterate rows
        for (row = 1; row <= row_count; row++)
        {
            //Inner loop to print space
            for (col = 0; col <= row; col++)
            {
                cout << " ";
            }
            //Inner loop to print characters
            for (col = 0; col <= row_count - row; col++)
            {
                cout << (char)(asciiValue + col) << " ";
            }
            //Prints a newline
            cout << endl;
        }
    }
    return 0;
}

Output:

Character : A
Rows : 5

  A B C D E
   A B C D
    A B C
     A B
      A

Java Program to Print Right Angled Triangle with Same Character Pattern

Program to Print Right Angled Triangle with Same Character Pattern

In this program we are going to see how to print the right angled triangle with same character pattern.

Example-1

When character=f 
and row value=3

f
f f
f f f
Example-2:

When character=A 

and row value=5

A
A A
A A A
A A A A
A A A A A

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

Are you wondering how to seek help from subject matter experts and learn the Java language? Go with these Basic Java Programming Examples and try to code all of them on your own then check with the exact code provided by expert programmers.

Approach:

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

JAVA CODE:

import java.util.Scanner;
class Main
{
public static void main(String[] args)
{
    Scanner scan = new Scanner(System.in);
    //Taking character to be printed as input from the user
    System.out.print("Character : ");
    char c = scan.next().charAt(0);

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

    int row, col;
    //Converting the character to its ascii value
    int asciiValue = (int) c;

    //Checks whether the character is a letter or not
    if(asciiValue>=65&&asciiValue<=122)
    {
        //Outer loop to iterate rows
        for(row = 0; row<row_count; row++)
        {
            //Inner loop to iterate columns
            for(col = 0; col<row+1; col++)
            {
                System.out.print(c+" ");
            }
            //Prints a newline
            System.out.println();
        }
    }
  }
}


Output:

Character : A
Rows : 5

A
A A
A A A
A A A A
A A A A A

C CODE:

#include <stdio.h>

int main()
{
    //Taking character to be printed as input from the user
    printf("Character : ");
    char c;
    scanf("%c", &c);

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

    int row, col;
    //Converting the character to its ascii value
    int asciiValue = (int)c;

    //Checks whether the character is a letter or not
    if (asciiValue >= 65 && asciiValue <= 122)
    {
        //Outer loop to iterate rows
        for (row = 0; row < row_count; row++)
        {
            //Inner loop to iterate columns
            for (col = 0; col < row + 1; col++)
            {
                printf("%c ", c);
            }
            //Prints a newline
            printf("\n");
        }
    }
    return 0;
}

Output:

Character : A
Rows : 5

A
A A
A A A
A A A A
A A A A A

C++ CODE

#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    //Taking character to be printed as input from the user
    cout << "Character : ";
    char c;
    cin >> c;

    //Taking number of rows as input from the user
    cout << "Rows : ";
    int row_count;
    cin >> row_count;

    int row, col;
    //Converting the character to its ascii value
    int asciiValue = (int)c;

    //Checks whether the character is a letter or not
    if (asciiValue >= 65 && asciiValue <= 122)
    {
        //Outer loop to iterate rows
        for (row = 0; row < row_count; row++)
        {
            //Inner loop to iterate columns
            for (col = 0; col < row + 1; col++)
            {
                cout << c << " ";
            }
            //Prints a newline
            cout << endl;
        }
    }
    return 0;
}


Output:

Character : A
Rows : 5

A
A A
A A A
A A A A
A A A A A

Related Java Star Pattern Programs:

Java Program to Print letters of a string in Inverted Right Angled Triangle Character Pattern

Printing letters of a string in Inverted Right Angled Triangle Pattern

In the previous article, we have discussed Java Program to Print Pyramid with Column wise Same Character Pattern

In this program we are going to see how to print Letters of a string in inverted right angle character pattern.

Example-1

When String value= Example

Example
Exampl
Examp
Exam
Exa
Ex
E
Example-2:

When String value= PatternString

PatternString
PatternStrin
PatternStri
PatternStr
PatternSt
PatternS
Pattern
Patter
Patte
Patt
Pat
Pa
P

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

Don’t miss the chance of Java programs examples with output pdf free download as it is very essential for all beginners to experienced programmers for cracking the interviews.

Approach:

  • Enter the string and store it in an variable str.
  • Take one outer for loop to iterate the rows,
  • Inside the for loop, take one for loop, one to print the string.
  • After each iteration print a newline.

Java Code to Print letters of a string in Inverted Right Angled Triangle Character Pattern

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

    //Taking string as input from the user
    System.out.print("String : ");
    String str = scan.nextLine();
    scan.close();

    int row,col;
    
    //Length of the string
    int len = str.length();
    //Coverting the String to a character array
    char[] charArray = str.toCharArray();

    //Outer loop to iterate rows
    for(row = len-1; row>=0; row--)
    {
        //Inner loop to iterate columns and print string
        for(col = 0; col<=row; col++)
        {
            System.out.print(charArray[col]);
        }
        //Prints a newline
        System.out.println();
    }
}  
}
Output:

String : BtechGeeks
BtechGeek
BtechGee
BtechGe
BtechG
Btech
Btec
Bte
Bt
B

C Code to Print letters of a string in Inverted Right Angled Triangle Character Pattern

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

int main()
{
    //Taking string as input from the user
    printf("String : ");
    char str[100];
    gets(str);

    int row, col;

    int len = strlen(str); //Length of the string               

    //Outer loop to iterate rows
    for (row = len - 1; row >= 0; row--)
    { 
        //Inner loop to iterate columns and print string
        for (col = 0; col <= row; col++)
        {
            printf("%c", str[col]);
        }
        //Prints a newline
        printf("\n");
    }
    return 0;
}

Output:

String : BtechGeeks
BtechGeek
BtechGee
BtechGe
BtechG
Btech
Btec
Bte
Bt
B

C++ Code to Print letters of a string in Inverted Right Angled Triangle Character Pattern

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

    char charArray[100];
    //Copying the String to a character array
    strcpy(charArray, str.c_str());

    int row, col;

    //Length of the character Array
    int len = strlen(charArray);

    //Outer loop to iterate rows
    for (row = len - 1; row >= 0; row--)
    {
        //Inner loop to iterate columns and print string
        for (col = 0; col <= row; col++)
        {
            cout << charArray[col];
        }
        //Prints a newline
        cout << endl;
    }
    return 0;
}
Output:

String : BtechGeeks
BtechGeek
BtechGee
BtechGe
BtechG
Btech
Btec
Bte
Bt
B

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:

Java Program to Print Pyramid with Column wise Increasing Character Pattern

Program to Print Pyramid with Column wise Increasing Character Pattern

In the previous article, we have discussed Java Program to Print Hollow Diamond within Rectangle Character Pattern

In this program we are going to see how to print the pyramid column wise increasing character pattern.

Example-1

When row value=5

        A   
      ABA  
    ABCBA 
  ABCDCBA
ABCDEDCBA
Example-2:

When row value=9

                A
              ABA
            ABCBA
          ABCDCBA
        ABCDEDCBA
      ABCDEFEDCBA
    ABCDEFGFEDCBA
  ABCDEFGHGFEDCBA
ABCDEFGHIHGFEDCBA

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

Are you wondering how to seek help from subject matter experts and learn the Java language? Go with these Basic Java Programming Examples and try to code all of them on your own then check with the exact code provided by expert programmers.

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 three inner for loops, one to print the space and the other for characters.
  • After each iteration print a new line.

Java Code to Print Pyramid with Column wise Increasing Character Pattern

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

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

    int row, col;
    //Outer for loop to iterate the rows
    for (row = 1; row <= row_count; row++)
    {
        //Loop to print space
        for (col = 1;col <=row_count-row;col++)
        {
            System.out.print(" ");
        }
        //Loop to print char
        for (col = 1; col <= row; col++)
        {
            System.out.print((char)(col+64));
        }
        //Loop to print char
        for ( col = row-1; col >= 1; col--)
        {
            System.out.print((char)(col+64));
        }
        //Prints a newline
        System.out.println();
    }
}  

}


Output

Rows : 9

              A
            ABA
          ABCBA
        ABCDCBA
      ABCDEDCBA
     ABCDEFEDCBA
   ABCDEFGFEDCBA
 ABCDEFGHGFEDCBA
ABCDEFGHIHGFEDCBA

C Code to Print Pyramid with Column wise Increasing Character Pattern

#include <stdio.h>

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

    int row, col;

    // Outer for loop to iterate the rows
    for (row = 1; row <= row_count; row++)
    {
        //Loop to print space
        for (col = 1; col <= row_count - row; col++)
        {
            printf(" ");
        }
        //Loop to print char
        for (col = 1; col <= row; col++)
        {
            printf("%c", (col + 64));
        }
        //Loop to print char
        for (col = row - 1; col >= 1; col--)
        {
            printf("%c", (col + 64));
        }
        //prints a newline
        printf("\n");
    }

    return 0;
}

Output:

Rows : 9

                A
              ABA
            ABCBA
          ABCDCBA
        ABCDEDCBA
      ABCDEFEDCBA
    ABCDEFGFEDCBA
  ABCDEFGHGFEDCBA
ABCDEFGHIHGFEDCBA

C++ Code to Print Pyramid with Column wise Increasing Character Pattern

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

    int row, col;

    // Outer for loop to iterate the rows
    for (row = 1; row <= row_count; row++)
    {
        //Loop to print space
        for (col = 1; col <= row_count - row; col++)
        {
            cout << " ";
        }
        //Loop to print char
        for (col = 1; col <= row; col++)
        {
            cout << (char)(col + 64);
        }
        //Loop to print char
        for (col = row - 1; col >= 1; col--)
        {
            cout << (char)(col + 64);
        }
        // prints a newline
        cout << endl;
    }
    return 0;
}

Output:

Rows : 9

                A
              ABA
            ABCBA
          ABCDCBA
        ABCDEDCBA
      ABCDEFEDCBA
    ABCDEFGFEDCBA
  ABCDEFGHGFEDCBA
ABCDEFGHIHGFEDCBA

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: