Java Program to Print Right Pascal Character Pattern

Program to Print Right Pascal Character Pattern

In the previous article, we have discussed Java Program to Print Sand Glass Character Pattern

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

Example-1

When row value=7

A
AB
ABC
ABCD
ABC
AB
A
Example-2:

When row value=11

A
AB
ABC
ABCD
ABCDE
ABCDEF
ABCDE
ABCD
ABC
AB
A

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

Provided list of Simple Java Programs is specially designed for freshers and beginners to get familiarize with the concepts of Java programming language and become pro in coding.

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 Right Pascal Character Pattern

import java.util.Scanner;
class Main
{
    public static void main(String[] args)  
    {  
        //Taking character to be printed as input from the user
        System.out.print("Character : ");
        Scanner scan = new Scanner(System.in);
        char c = scan.next().charAt(0);
    
        //Taking number of rows as input from the user
        System.out.print("Rows(enter odd number) : ");
        int row_count = scan.nextInt();
        row_count = (row_count) / 2;
        //Making the row count half to print each half of the pattern
    
        int row, col;
    
        int asciiValue = (int)c;
        //Converting the character to its ascii value
    
        for (row = 0; row <= row_count; row++)
        {
            //Outer loop to print upper half
            for (col = 0; col <= row; col++)
            {
                System.out.print((char)(asciiValue + col));
            }
            System.out.println();
            //Prints a newline
        }
    
        for (row = row_count - 1; row >= 0; row--)
        {
            //Inner loop to print upper half
            for (col = 0; col <= row; col++)
            {
                System.out.print((char) (asciiValue + col));
            }
            System.out.println();
            //Prints a newline
        }
    }  
}

Output:

Character : A
Rows(enter odd number) : 5

A
AB
ABC
AB
A

C Code to Print Right Pascal 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(enter odd number) : ");
    int row_count;
    scanf("%d", &row_count);
    row_count = (row_count) / 2;
    //Making the row count half to print each half of the pattern

    int row, col;

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

    for (row = 0; row <= row_count; row++)
    {
        //Outer loop to print upper half
        for (col = 0; col <= row; col++)
        {
            printf("%c ", (asciiValue + col));
        }
        printf("\n");
        //Prints a newline
    }

    for (row = row_count - 1; row >= 0; row--)
    {
        //Inner loop to print upper half
        for (col = 0; col <= row; col++)
        {
            printf("%c ", (asciiValue + col));
        }
        printf("\n");
        //Prints a newline
    }

    return 0;
}

Output:

Character : A
Rows(enter odd number) : 5

A
AB
ABC
AB
A

C++ Code to Print Right Pascal 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(enter odd number) : ";
    int row_count;
    cin >> row_count;
    row_count = (row_count) / 2;
    //Making the row count half to print each half of the pattern

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

    for (row = 0; row <= row_count; row++)
    {
        //Outer loop to print upper half
        for (col = 0; col <= row; col++)
        {
            cout << (char)(asciiValue + col);
        }
        cout << endl;
        //Prints a newline
    }

    for (row = row_count - 1; row >= 0; row--)
    {
        //Inner loop to print upper half
        for (col = 0; col <= row; col++)
        {
            cout << (char)(asciiValue + col);
        }
        cout << endl;
        //Prints a newline
    }
    return 0;
}
Output:

Character : A
Rows(enter odd number) : 5

A
AB
ABC
AB
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 Hollow Diamond within Rectangle Character Pattern

Program to Print Hollow Diamond within Rectangle Character Pattern

In the previous article, we have discussed Java Program to Print Right Pascal Character Pattern

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

Example-1

When row value=5

ABCBA
AB  BA
A      A
AB  BA
ABCBA
Example-2:

When row value=11

ABCDEFEDCBA
ABCDE EDCBA
ABCD     DCBA
ABC          CBA
AB              BA
A                  A
AB              BA
ABC          CBA
ABCD     DCBA
ABCDE  EDCBA
ABCDEFEDCBA

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 two outer for loops, one for the upper half and the other for the bottom.
  • Inside both the loops, take three inner for loops, one to print the space and the other two for characters.
  • After each iteration print a newline.

Java Code to Print Hollow Diamond within Rectangle 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(enter odd number) : ");
        int row_count = scan.nextInt();
        row_count=row_count/2;
        //Making the row count half to print each half of the pattern
    
        int row, col;
    
        int asciiValue = 65;
        //ASCII of A is 65
    
        for (row = 0; row <= row_count; row++)
        {
            //Outer loop to print upper half
            for (col = 0; col <= row_count-row; col++)
            {
                //Loop to print character
                System.out.print((char)(asciiValue + col));
            }
    
            for (col = 1; col <= row*2-1; col++)
            {
                //Loop to print space
                System.out.print(" ");
            }
            
            for (col = row_count-row; col >= 0; col--)
            {
                //Loop to print character
                if(col!=row_count)
                    System.out.print((char)(asciiValue + col));  
            }
            
            System.out.println();
            //Prints a newline
        }
    
        for (row = row_count - 1; row >= 0; row--)
        {
            //Inner loop to print lower half
            for (col = 0; col <= row_count-row; col++)
            {
                //Loop to print character
                System.out.print((char)(asciiValue + col));
            }
    
            for (col = 1; col <= row*2-1; col++)
            {
                //Loop to print space
                System.out.print(" ");
            }
            
            for (col = row_count-row; col >= 0; col--)
            {
                //Loop to print character
                if(col!=row_count)
                    System.out.print((char)(asciiValue + col));  
            }
            
            System.out.println();
            //Prints a new line
        }
    }  

}

Output:

Rows(enter odd number) : 11

ABCDEFEDCBA
ABCDE  EDCBA
ABCD     DCBA
ABC          CBA
AB              BA
A                  A
AB              BA
ABC          CBA
ABCD     DCBA
ABCDE  EDCBA
ABCDEFEDCBA

C Code to Print Hollow Diamond within Rectangle Character Pattern

#include <stdio.h>

int main()
{
    //Taking number of rows as input from the user
    printf("Rows(enter odd number) : ");
    int row_count;
    scanf("%d", &row_count);
    row_count = (row_count) / 2;
    //Making the row count half to print each half of the pattern

    int row, col;

    int asciiValue = 65;
    //ASCII value of A is 65

    for (row = 0; row <= row_count; row++)
    {
        //Outer loop to print upper half
        for (col = 0; col <= row_count - row; col++)
        {
            //Loop to print character
            printf("%c", (asciiValue + col));
        }

        for (col = 1; col <= row * 2 - 1; col++)
        {
            //Loop to print space
            printf(" ");
        }

        for (col = row_count - row; col >= 0; col--)
        {
            //Loop to print character
            if (col != row_count)
                printf("%c", (asciiValue + col));
        }
        printf("\n");
        //Prints a newline
    }

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

        for (col = 1; col <= row * 2 - 1; col++)
        {
            //Loop to print space
            printf(" ");
        }

        for (col = row_count - row; col >= 0; col--)
        {
            //Loop to print character
            if (col != row_count)
                printf("%c", (asciiValue + col));
        }
        printf("\n");
        //Prints a newline
    }

    return 0;
}
Output

Rows(enter odd number) : 11

ABCDEFEDCBA
ABCDE EDCBA
ABCD     DCBA
ABC          CBA
AB              BA
A                  A
AB              BA
ABC          CBA
ABCD     DCBA
ABCDE  EDCBA
ABCDEFEDCBA

C++ Code to Print Hollow Diamond within Rectangle 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(enter odd number) : ";
    int row_count;
    cin >> row_count;
    row_count /= 2;

    int row, col;
    //Converting the character to its ascii value
    int asciiValue = 65;
    //ASCII value of A is 65

    for (row = 0; row <= row_count; row++)
    {
        //Outer loop to print upper half
        for (col = 0; col <= row_count - row; col++)
        {
            //Loop to print character
            cout << (char)(asciiValue + col);
        }

        for (col = 1; col <= row * 2 - 1; col++)
        {
            //Loop to print space
            cout << " ";
        }

        for (col = row_count - row; col >= 0; col--)
        {
            //Loop to print character
            if (col != row_count)
                cout << (char)(asciiValue + col);
        }
        cout << endl;
        //Prints a newline
    }

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

        for (col = 1; col <= row * 2 - 1; col++)
        {
            //Loop to print space
            cout << " ";
        }

        for (col = row_count - row; col >= 0; col--)
        {
            //Loop to print character
            if (col != row_count)
                cout << (char)(asciiValue + col);
        }
        cout << endl;
        //Prints a newline
    }
    return 0;
}
Output:

Rows(enter odd number) : 11

ABCDEFEDCBA
ABCDE  EDCBA
ABCD      DCBA
ABC           CBA
AB                BA
A                    A
AB                BA
ABC           CBA
ABCD      DCBA
ABCDE  EDCBA
ABCDEFEDCBA

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 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: