Java Program to Print Reverse K Shape Character Pattern

Program to Print Reverse K Shape Character Pattern

In the previous article, we have discussed Java Program to Print K Shape with Decreasing Character Pattern

In this program we are going to see how to print the Reverse K shape character pattern.

Example-1

When row value=6

ABC
  BC
    C
    C
  BC
ABC
Example-2:

When row value=10

ABCDE
  BCDE
    CDE
      DE
        E
        E
      DE
    CDE
  BCDE
ABCDE

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 total row and store it in an integer variable row_count.
  • Take two outer for loops, one for the upper half and the other for the bottom.
  • Inside both the loops, take two inner for loops to print the space and the characters.
  • After each iteration print a new line.

Java Code to Print Reverse K Shape 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 and
        //then dividing it by two to get the size of the halves
        System.out.print("Rows(Enter even number) : ");
        int row_count = scan.nextInt();
        row_count/=2;
        
    
        int row, col, alphaAscii;
        //row, col are iterator and 
        //the alphaAscii is the 
        //ASCII value holder initialized to hold 'A'
    
        //loop to print upper part of the pattern
        for (row = 0; row <= row_count - 1; row++)
        {
            //Resetting the value to 'A' after every iteration
            alphaAscii = 65;
            
            for (col = 0; col < row; col++)
            {
                //Inner loop to print space
                System.out.print(" ");
            }
            for (col = row; col <= row_count-1; col++)
            {
            
                System.out.print((char)(alphaAscii+col));
            }
            System.out.println();
        }
        
        //loop to print lower part of the pattern
        for (row = row_count - 1; row >= 0; row--)
        {
            //Resetting the value to 'A' after every iteration
            alphaAscii = 65;
            
            for (col = 0; col < row; col++)
            {
                    //Inner loop to print space
                    System.out.print(" ");
            }
             //Inner loop to print character
            for (col = row; col <= row_count-1; col++)
            {
                System.out.print((char)(alphaAscii+col));
            }
            System.out.println();
        }
    }
}

Output:

Rows(Enter even number) : 10

ABCDE
  BCDE
    CDE
      DE
        E
        E
      DE
    CDE
  BCDE
ABCDE

C Code to Print Reverse K Shape Character Pattern

#include <stdio.h>

int main()
{
    printf("Rows(Enter odd number) : ");
    int row_count;
    scanf("%d", &row_count);
    row_count /= 2;
    //Taking number of rows as input from the user and
    //then dividing it by two to get the size of the halves

    int row, col, alphaAscii;
    //row, col are iterator and the alphaAscii is the ASCII value holder

    for (row = 0; row <= row_count - 1; row++)
    {
        //loop to print upper part of the pattern
        alphaAscii = 65;
        //Resetting the value to 'A' after every iteration
        for (col = 0; col < row; col++)
        {
            //Inner loop to print space
            printf(" ");
        }
        for (col = row; col <= row_count - 1; col++)
        {
            //Inner loop to print character
            printf("%c", (char)(alphaAscii + col));
        }
        printf("\n");
    }
    for (row = row_count - 1; row >= 0; row--)
    {
        //loop to print lower part of the pattern
        alphaAscii = 65;
        //Resetting the value to 'A' after every iteration
        for (col = 0; col < row; col++)
        {
            //Inner loop to print space
            printf(" ");
        }
        for (col = row; col <= row_count - 1; col++)
        {
            //Inner loop to print character
            printf("%c", (char)(alphaAscii + col));
        }
        printf("\n");
    }
    return 0;
}

Output:

Rows(Enter even number) : 10

ABCDE
  BCDE
    CDE
      DE
        E
        E
      DE
    CDE
  BCDE
ABCDE

C++ Code to Print Reverse K Shape Character Pattern

#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    cout << "Rows(Enter even number) : ";
    int row_count;
    cin >> row_count;
    row_count /= 2;
    //Taking number of rows as input from the user and
    //then dividing it by two to get the size of the halves

    int row, col, alphaAscii = 65;
    //row, col are iterator and the alphaAscii is the ASCII value holder

    for (row = 0; row <= row_count - 1; row++)
    {
        //loop to print upper part of the pattern
        alphaAscii = 65;
        //Resetting the value to 'A' after every iteration
        for (col = 0; col < row; col++)
        {
            //Inner loop to print space
            cout << " ";
        }
        for (col = row; col <= row_count - 1; col++)
        {
            //Inner loop to print character
            cout << (char)(alphaAscii + col);
        }
        cout << endl;
    }
    for (row = row_count - 1; row >= 0; row--)
    {
        //loop to print lower part of the pattern
        alphaAscii = 65;
        //Resetting the value to 'A' after every iteration
        for (col = 0; col < row; col++)
        {
            //Inner loop to print space
            cout << " ";
        }
        for (col = row; col <= row_count - 1; col++)
        {
            //Inner loop to print character
            cout << (char)(alphaAscii + col);
        }
        cout << endl;
    }

    return 0;
}
Output:

Rows(Enter even number) : 10

ABCDE
  BCDE
    CDE
      DE
        E
        E
      DE
    CDE
  BCDE
ABCDE

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 Sand Glass Character Pattern

Program to Print Sand Glass Character Pattern

In the previous article, we have discussed Java Program to Print Reverse K Shape Character Pattern

In this program we are going to see how to print the sand glass character pattern.

Example-1

When row value=6

A B C
 B C
  C
  C
 B C
A B C
Example-2:

When row value=10

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

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 total row and store it in an integer variable row_count.
  • Take two outer for loops, one for the upper half and the other for the bottom.
  • Inside both the loops, take two inner for loops to print the space and the characters.
  • After each iteration print a new line.

Java Code to Print Sand Glass Character Pattern

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

    System.out.print("Rows(Enter even number) : ");
    int row_count = scan.nextInt();
    row_count/=2;
    //Taking number of rows as input from the user and
    //then dividing it by two to get the size of the halves

    int row, col, alphaAscii;
    //row, col are iterator and the alphaAscii is the ASCII value holder initialized to hold 'A'

    for (row = 0; row <= row_count - 1; row++)
    {
        //loop to print upper part of the pattern
        alphaAscii = 65;
        //Resetting the value to 'A' after every iteration
        for (col = 0; col < row; col++)
        {
        //Inner loop to print space
                System.out.print(" ");
        }
        for (col = row; col <= row_count-1; col++)
        {
        //Inner loop to print character
            System.out.print((char)(alphaAscii+col)+" ");
        }
        System.out.println();
    }
    for (row = row_count - 1; row >= 0; row--)
    {
        //loop to print lower part of the pattern
        alphaAscii = 65;
        //Resetting the value to 'A' after every iteration
        for (col = 0; col < row; col++)
        {
        //Inner loop to print space
                System.out.print(" ");
        }
        for (col = row; col <= row_count-1; col++)
        {
        //Inner loop to print character
            System.out.print((char)(alphaAscii+col)+" ");
        }
        System.out.println();
    }
}
}


Output:

Rows(Enter even number) : 10

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

C Code to Print Sand Glass Character Pattern

#include <stdio.h>

int main()
{
    printf("Rows(Enter odd number) : ");
    int row_count;
    scanf("%d", &row_count);
    row_count /= 2;
    //Taking number of rows as input from the user and
    //then dividing it by two to get the size of the halves

    int row, col, alphaAscii;
    //row, col are iterator and the alphaAscii is the ASCII value holder

    for (row = 0; row <= row_count - 1; row++)
    {
        //loop to print upper part of the pattern
        alphaAscii = 65;
        //Resetting the value to 'A' after every iteration
        for (col = 0; col < row; col++)
        {
            //Inner loop to print space
            printf(" ");
        }
        for (col = row; col <= row_count - 1; col++)
        {
            //Inner loop to print character
            printf("%c ", (char)(alphaAscii + col));
        }
        printf("\n");
    }
    for (row = row_count - 1; row >= 0; row--)
    {
        //loop to print lower part of the pattern
        alphaAscii = 65;
        //Resetting the value to 'A' after every iteration
        for (col = 0; col < row; col++)
        {
            //Inner loop to print space
            printf(" ");
        }
        for (col = row; col <= row_count - 1; col++)
        {
            //Inner loop to print character
            printf("%c ", (char)(alphaAscii + col));
        }
        printf("\n");
    }
    return 0;
}

Output:

Rows(Enter even number) : 10

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

C++ Code to Print Sand Glass Character Pattern

#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    cout << "Rows(Enter even number) : ";
    int row_count;
    cin >> row_count;
    row_count /= 2;
    //Taking number of rows as input from the user and
    //then dividing it by two to get the size of the halves

    int row, col, alphaAscii = 65;
    //row, col are iterator and the alphaAscii is the ASCII value holder

    for (row = 0; row <= row_count - 1; row++)
    {
        //loop to print upper part of the pattern
        alphaAscii = 65;
        //Resetting the value to 'A' after every iteration
        for (col = 0; col < row; col++)
        {
            //Inner loop to print space
            cout << " ";
        }
        for (col = row; col <= row_count - 1; col++)
        {
            //Inner loop to print character
            cout << (char)(alphaAscii + col)<<” “;
        }
        cout << endl;
    }
    for (row = row_count - 1; row >= 0; row--)
    {
        //loop to print lower part of the pattern
        alphaAscii = 65;
        //Resetting the value to 'A' after every iteration
        for (col = 0; col < row; col++)
        {
            //Inner loop to print space
            cout << " ";
        }
        for (col = row; col <= row_count - 1; col++)
        {
            //Inner loop to print character
            cout << (char)(alphaAscii + col)<<” “;
        }
        cout << endl;
    }

    return 0;
}

Output:

Rows(Enter even number) : 10

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

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 K Shape with Increasing Character Pattern

Program to Print K Shape with Increasing Character Pattern

In the previous article, we have discussed Java Program to Print Diamond with Repeated Character Pattern

In this program we are going to see how to print the K shape increasing character pattern.

Example-1

When row value=6

A B C
A B
A
A
A B
A B C


Example-2:

When row value=10

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

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 total row and store it in an integer variable row_count.
  • Take two outer for loops, one for the upper half and the other for the bottom.
  • Inside both the loops, take one inner loop to print the character.
  • After each iteration print a newline.

Java Code to Print K Shape with Increasing Character Pattern

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

    System.out.print("Rows(Enter even number) : ");
    int row_count = scan.nextInt();
    row_count/=2;
    //Taking number of rows as input from the user and
    //then dividing it by two to get the size of the halves

    int row, col, alphaAscii;
    //row, col are iterator and the alphaAscii is the ASCII value holder initialized to hold 'A'

    for (row = row_count - 1; row >= 0; row--)
    {
        //loop to print upper part of the pattern
        alphaAscii = 65;
        for (col = 0; col <= row; col++)
        {
            System.out.print((char)(alphaAscii+col)+ " ");
        }
        System.out.println();
    }
    for (row = 0; row <= row_count - 1; row++)
    {
        //loop to print lower part of the pattern
        alphaAscii = 65;
        for (col = 0; col <= row; col++)
        {
            System.out.print((char)(alphaAscii+col)+ " ");
        }
        System.out.println();
    }
}
}

Output:

Rows(Enter even number) : 10

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

C Code to Print K Shape with Increasing Character Pattern

#include <stdio.h>

int main()
{
    printf("Rows(Enter odd number) : ");
    int row_count;
    scanf("%d", &row_count);
    row_count /= 2;
    //Taking number of rows as input from the user and
    //then dividing it by two to get the size of the halves

    int row, col, alphaAscii;
    //row, col are iterator and the alphaAscii is the ASCII value holder

    for (row = row_count - 1; row >= 0; row--)
    {
        //loop to print lower part of the pattern
        alphaAscii = 65;
        //Resetting the value to 'A' after every iteration
        for (col = 0; col <= row; col++)
        {
            printf("%c ", (char)(alphaAscii + col));
        }
        printf("\n");
    }
    for (row = 0; row <= row_count - 1; row++)
    {
        //loop to print lower part of the pattern
        alphaAscii = 65;
        //Resetting the value to 'A' after every iteration
        for (col = 0; col <= row; col++)
        {
            //Inner loop to print characters starting from 'A'
            printf("%c ", (char)(alphaAscii + col));
        }
        printf("\n");
    }
    return 0;
}
Output:

Rows(Enter even number) : 10

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

C++ Code to Print K Shape with Increasing Character Pattern

#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    cout << "Rows(Enter even number) : ";
    int row_count;
    cin >> row_count;
    row_count /= 2;
    //Taking number of rows as input from the user and
    //then dividing it by two to get the size of the halves

    int row, col, alphaAscii = 65;
    //row, col are iterator and the alphaAscii is the ASCII value holder

    for (row = row_count - 1; row >= 0; row--)
    {
        //loop to print lower part of the pattern
        alphaAscii = 65;
        //Resetting the value to 'A' after every iteration
        for (col = 0; col <= row; col++)
        {
            cout << (char)(alphaAscii + col) << " ";
        }
        cout << endl;
    }

    for (row = 0; row <= row_count - 1; row++)
    {
        //loop to print lower part of the pattern
        alphaAscii = 65;
        //Resetting the value to 'A' after every iteration
        for (col = 0; col <= row; col++)
        {
            cout << (char)(alphaAscii + col) << " ";
        }
        cout << endl;
    }

    return 0;
}

Output:

Rows(Enter even number) : 10

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

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 K Shape with Decreasing Character Pattern

Program to Print K Shape with Decreasing Character Pattern

In the previous article, we have discussed Java Program to Print K Shape with Increasing Character Pattern

In this program we are going to see how to print the K shape decreasing character pattern.

Example-1

When row value=6

C B A
B A
A
A
B A
C B A
Example-2:

When row value=10

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

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 total row and store it in an integer variable row_count.
  • Take two outer for loops, one for the upper half and the other for the bottom.
  • Inside both the loops, take one inner loop to print the character.
  • After each iteration print a newline.

Java Code to Print K Shape with Decreasing Character Pattern

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

    System.out.print("Rows(Enter even number) : ");
    int row_count = scan.nextInt();
    row_count/=2;
    //Taking number of rows as input from the user and
    //then dividing it by two to get the size of the halves

    int row, col, alphaAscii;
    //row, col are iterator and the alphaAscii is the ASCII value holder

    for (row = row_count - 1; row >= 0; row--)
    {
        //loop to print upper part of the pattern
        alphaAscii = 65;
        //Resetting the value to 'A' after every iteration
        for (col = row; col >= 0; col--)
        {
            System.out.print((char)(alphaAscii+col)+ " ");
        }
        System.out.println();
    }
    for (row = 0; row <= row_count - 1; row++)
    {
        //loop to print lower part of the pattern
        alphaAscii = 65;
        //Resetting the value to 'A' after every iteration
        for (col = row; col >= 0; col--)
        {
            System.out.print((char)(alphaAscii+col)+ " ");
        }
        System.out.println();
    }
}
}

Output:

Rows(Enter even number) : 10

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

C Code to Print K Shape with Decreasing Character Pattern

#include <stdio.h>

int main()
{
    printf("Rows(Enter odd number) : ");
    int row_count;
    scanf("%d", &row_count);
    row_count /= 2;
    //Taking number of rows as input from the user and
    //then dividing it by two to get the size of the halves

    int row, col, alphaAscii;
    //row, col are iterator and the alphaAscii is the ASCII value holder

    for (row = row_count - 1; row >= 0; row--)
    {
        //loop to print lower part of the pattern
        alphaAscii = 65;
        //Resetting the value to 'A' after every iteration
        for (col = row; col >= 0; col--)
        {
            printf("%c ", (char)(alphaAscii + col));
        }
        printf("\n");
    }
    for (row = 0; row <= row_count - 1; row++)
    {
        //loop to print lower part of the pattern
        alphaAscii = 65;
        //Resetting the value to 'A' after every iteration
        for (col = row; col >= 0; col--)
        {
            //Inner loop to print characters starting from 'A'
            printf("%c ", (char)(alphaAscii + col));
        }
        printf("\n");
    }
    return 0;
}
Output:

Rows(Enter even number) : 10

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

C++ Code to Print K Shape with Decreasing Character Pattern

#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    cout << "Rows(Enter even number) : ";
    int row_count;
    cin >> row_count;
    row_count /= 2;
    //Taking number of rows as input from the user and
    //then dividing it by two to get the size of the halves

    int row, col, alphaAscii = 65;
    //row, col are iterator and the alphaAscii is the ASCII value holder

    for (row = row_count - 1; row >= 0; row--)
    {
        //loop to print lower part of the pattern
        alphaAscii = 65;
        //Resetting the value to 'A' after every iteration
        for (col = row; col >= 0; col--)
        {
            cout << (char)(alphaAscii + col) << " ";
        }
        cout << endl;
    }

    for (row = 0; row <= row_count - 1; row++)
    {
        //loop to print lower part of the pattern
        alphaAscii = 65;
        //Resetting the value to 'A' after every iteration
        for (col = row; col >= 0; col--)
        {
            cout << (char)(alphaAscii + col) << " ";
        }
        cout << endl;
    }

    return 0;
}

Output:

Rows(Enter even number) : 10

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

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 Increasing Character Pattern

Printing Pyramid with Increasing Character Pattern

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

Let’s see the example first.

Example-1

When row value=6
         A
       A B
     A B C
   A B C D
  A B C D E
A B C D E F
Example-2:

When row value=5

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

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 new line.

JAVA CODE:

import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        // Scannr class object created 
        Scanner scan = new Scanner(System.in);
        
        //Taking number of rows as 
        //input from the user 
        System.out.print("Rows : "); 
        int row_count = scan.nextInt(); 
        
        // for loop to print the number of rows
        for (int row = 0; row <= row_count; row++)
        {
            int c = 65;
            // for loop to print the column values 
            // here printing space
            for (int col = 5; col > row; col--)
            {
                System.out.print(" ");
            }
            // for loop to print the column values 
            // here printing the character value
            for (int k = 0; k < row; k++)
            {
                System.out.print((char) (c + k) + " ");
            }
            // one row printing completed 
            // moving to the next line
            System.out.println();
        }
    }
}
Output:

Rows: 5

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

Related Java Star Pattern Programs:

Java Program to Print Triangle with Repeated Character (Increasing Order) Pattern

Print Triangle with Repeated Character (Increasing Order)

In the previous article, we have discussed Java Program to Print Right Angled Triangle with Increasing Alternate Case Character Pattern

In this program we are going to see how to print triangle with repeated character in increasing order pattern.

Example-1

When character=a 
and row value=4

    a
   b b
  c c c
d d d d
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.

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 newline.

Java Code to Print Triangle with Repeated Character (Increasing Order) 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((char)(asciiValue+row)+" ");
                }
                //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 to Print Triangle with Repeated Character (Increasing Order) 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 ", (char)(asciiValue + row));
            }
            //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 to Print Triangle with Repeated Character (Increasing Order) 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 << (char)(asciiValue + row) << " ";
            }
            //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

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 Decreasing Character Pattern

Printing Pyramid with Decreasing Character Pattern

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

Let’s see the example first.

Example-1

When row value=6
         
        F
       E F
     D E F
   C D E F
  B C D E F
A B C D E F
Example-2:

When row value=5

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

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.*;

public class Main
{
    public static void main(String[] args)
    {   
        //Scanner class object created
        Scanner scan=new Scanner(System.in);
        
        // Enter number of rows as 
        // input from the User
        System.out.print("Rows : ");
        int row_count=scan.nextInt();

        // for loop to print all the rows
        for (int row = row_count; row >= 0; row--)
        {
            int c = 65;
            // for loop to print column values
            // here printing space as column valu
            for (int col = 0; col < row; col++)
            {
                System.out.print(" ");
            }
            //for loop to print column values
            //here printing character as column valu
            for (int k = row; k < row_count; k++)
            {
                System.out.print((char) (c + k) + " ");
            }
            // one row printed
            // moving to next line
            System.out.println();
        }

    }
}
Output:

Rows : 5

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

Related Java Star Pattern Programs:

Java Program to Print Triangle with Repeated Character (Decreasing Order) Pattern

Print Triangle with Repeated Character (Decreasing Order)

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

In this program we are going to see how to print triangle with repeated character in decreasing order pattern.

Example-1

When character=h 
and row value=4

   h
  g g
 f  f  f
e e e e
Example-2:

When character=F 
and row value=5

       F
     E E
   D D D
  C C C C
 B B B B B

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 to Print Triangle with Repeated Character (Decreasing Order) 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((char)(asciiValue-row)+" ");
                }
                //Prints a newline
                System.out.println();
            }
        }
    }
}

Output:

Character : F
Rows : 5

      F
     E E
   D D D
  C C C C
 B B B B B

C Code to Print Triangle with Repeated Character (Decreasing Order) 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 ", (char)(asciiValue - row));
            }
            //Prints a newline
            printf("\n");
        }
    }
    return 0;
}
Output:

Character : F
Rows : 5

      F
     E E
   D D D
  C C C C
 B B B B B

C++ Code to Print Triangle with Repeated Character (Decreasing Order) 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 << (char)(asciiValue - row) << " ";
            }
            //Prints a newline
            cout << endl;
        }
    }
    return 0;
}

Output:

Character : F
Rows : 5

       F
     E E
   D D D
  C C C C
 B B B B 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 Right Angled-Triangle with odd number of Characters Pattern

Printing Right Angled-Triangle with odd number of Characters Pattern

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

 

Example-1

When character=h & row value=3

h
h i j
h I j k l
Example-2:

When character=A & row value=5

A
A B C
A B C D E
A B C D E F G
A B C D E F G H I

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 = 1; row <= row_count; row++)
            {
                //Reseting the character after each iteration
                asciiValue = c;
                //Inner loop to iterate columns
                for (col = 1; col <= row * 2 - 1; col++)
                {
                    System.out.print((char)(asciiValue)+" ");
                    asciiValue++;
                }
                //Prints a new line
                System.out.println();
            }
        }
    }
}
Output:

Character : A
Rows : 5

A
A B C
A B C D E
A B C D E F G
A B C D E F G H I

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 = 1; row <= row_count; row++)
        {
            //Reseting the character after each iteration
            asciiValue = c;
            //Inner loop to iterate columns
            for (col = 1; col <= row * 2 - 1; col++)
            {
                printf("%c ", (char)(asciiValue));
                asciiValue++;
            }
            //Prints a newline
            printf("\n");
        }
    }
    return 0;
}
Output:

Character : A
Rows : 5

A
A B C
A B C D E
A B C D E F G
A B C D E F G H I

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 = 1; row <= row_count; row++)
        {
            //Reseting the character after each iteration
            asciiValue = c;
            //Inner loop to iterate columns
            for (col = 1; col <= row * 2 - 1; col++)
            {
                cout << (char)asciiValue << " ";
                asciiValue++;
            }
            //Prints a newline
            cout << endl;
        }
    }
    return 0;
}

Output:

Character : A
Rows : 5

A
A B C
A B C D E
A B C D E F G
A B C D E F G H I

Related Java Star Pattern Programs:

Java Program to Print Diamond Character Pattern

Program to Print Diamond Character Pattern

In the previous article, we have discussed Java Program to Print Inverted Right-Angled Triangle with Row wise Decreasing Character Pattern

In this program we are going to see how to print the diamond character pattern.

Example-1

When row value=5

   A
  A B
 A B C
  A B
   A

 

Example-2:

When row value=9

     A
    A B
   A B C
  A B C D
 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.

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 total row and store it in an integer variable row_count.
  • Take two outer for loops, one for the upper half and the other for the bottom.
  • Inside both the loops, take two inner for loops to print the space and the characters.
  • After each iteration print a newline.

Java Code to Print Diamond 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 and
    System.out.print("Rows(Enter odd number) : ");
    int row_count = scan.nextInt();
    //then dividing it by two to get the size of the halves
    row_count/=2;
    
    //row, col are iterator and 
    //the alphaAscii is the ASCII value holder
    int row, col, alphaAscii;
    
     //loop to print upper part of the pattern
    for(row = 0; row<=row_count;row++)
    {
        //Resetting the alphabet to 'A' for every iteration
        alphaAscii = 65;
        //Inner loop to print space
        for(col = row_count; col>=row; col--)
        {
            // printing space
            System.out.print(" ");
        }
        //Inner loop to print characters starting from 'A'
        for(col = 0; col<=row;col++)
        {
            // printing character
            System.out.print((char) (alphaAscii+col)+" ");
        }
        System.out.println();
    }

    //loop to print lower part of the pattern
    for(row = 0;row<=row_count;row++)
    {
        //Resetting the alphabet to 'A' for every iteration
        alphaAscii = 65;
        //Inner loop to print space
        for(col = -1; col<=row;col++)
        {
            // printing space
            System.out.print(" ");
        }
         //Inner loop to print characters starting from 'A'
        for(col = 0; col<row_count-row; col++)
        {
            // printing character
            System.out.print((char) (alphaAscii+col)+" ");
        }
        System.out.println();
    }
}
}

Output:

Rows(Enter odd number) : 9

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

C Code to Print Diamond Character Pattern

#include <stdio.h>

int main()
{
    //Taking number of rows as input from the user and
    printf("Rows(Enter odd number) : ");
    int row_count;
    scanf("%d", &row_count);
    //then dividing it by two to get the size of the halves
    row_count /= 2;
    
    //row, col are iterator and 
    //the alphaAscii is the ASCII value holder
    int row, col, alphaAscii;
    
    //loop to print upper part of the pattern
    for (row = 0; row <= row_count; row++)
    {
        //Resetting the alphabet to 'A' for every iteration
        alphaAscii = 65;
        //Inner loop to print space
        for (col = row_count; col >= row; col--)
        {
            printf(" ");
        }
        //Inner loop to print characters starting from 'A'
        for (col = 0; col <= row; col++)
        {
            printf("%c ", (char)(alphaAscii + col));
        }
        printf("\n");
    }
    //loop to print lower part of the pattern
    for (row = 0; row <= row_count; row++)
    {
         //Resetting the alphabet to 'A' for every iteration
        alphaAscii = 65;
        //Inner loop to print space
        for (col = -1; col <= row; col++)
        {
            printf(" ");
        }
        //Inner loop to print characters starting from 'A'
        for (col = 0; col < row_count - row; col++)
        {
            printf("%c ", (char)(alphaAscii + col));
        }
        printf("\n");
    }
    return 0;
}
Output:

Rows(Enter odd number) : 9

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

C++ Code to Print Diamond Character Pattern

#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    cout << "Rows(Enter odd number) : ";
    int row_count;
    cin >> row_count;
    row_count /= 2;
    //Taking number of rows as input from the user and
    //then dividing it by two to get the size of the halves

    int row, col, alphaAscii;
    //row, col are iterator and the alphaAscii is the ASCII value holder

    for (row = 0; row <= row_count; row++)
    {
        //loop to print upper part of the pattern
        alphaAscii = 65;
        //Resetting the alphabet to 'A' for every iteration
        for (col = row_count; col >= row; col--)
        {
            //Inner loop to print space
            cout << " ";
        }

        for (col = 0; col <= row; col++)
        {
            //Inner loop to print characters starting from 'A'
            cout << (char)(alphaAscii + col) << " ";
        }
        cout << endl;
    }

    for (row = 0; row <= row_count; row++)
    {
        //loop to print lower part of the pattern
        alphaAscii = 65;
        //Resetting the alphabet to 'A' for every iteration
        for (col = -1; col <= row; col++)
        {
            //Inner loop to print space
            cout << " ";
        }

        for (col = 0; col < row_count - row; col++)
        {
            //Inner loop to print characters starting from 'A'
            cout << (char)(alphaAscii + col) << " ";
        }
        cout << endl;
    }
    return 0;
}

Output:

Rows(Enter odd number) : 9

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

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: