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:

Java Program to Print Right Angled Triangle with Row wise Increasing Character Pattern

Printing Right Angled Triangle with Row wise Increasing Character Pattern

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

Example-1

When character=h 
and row value=3

h
h i
h i j
Example-2:

When character=A 
and 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.

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 the character and store it in a variable c.
  • Then enter total row and store it in an integer variable row_count.
  • Take one outer for loop to iterate the rows.
  • Take one inner loop to iterate the columns and print the character.
  • After each iteration print a new line.

JAVA CODE:

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

Character : A
Rows : 5

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

C CODE:

#include <stdio.h>

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

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

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

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

Character : A
Rows : 5

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

C++ CODE:

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

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

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

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

Output:

Character : A
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 Alphabet A character Pattern

Program to Print Alphabet A character Pattern

In the previous article, we have discussed Java Program to Print Alphabet T Character Pattern

In this article we are going to see how to print the alphabet A character pattern.

Output:

Enter rows : 8

ABC 
A     D
A     D
ABCD
A     D
A     D
A     D

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:

  • We will take the number of rows as 8 and store it in n.
  • First we will use a for loop to print the vertical lines
  • We are going to use the if..else condition to print the horizontal line.
  • After each iteration we will print a new line.

Java Code to Print Alphabet A character Pattern

import java.util.Scanner;
public class pattern  
{  
    public static void main(String[] args)  
    {  
        int ascii=65;
        Scanner scan = new Scanner(System.in);
        //Taking input as 8 for our A
        System.out.print("Enter rows : ");
        int r, c, rows= scan.nextInt();  
        // Outer for loop 
        for (r = 0; r<=rows; r++)   
        {  
        // Inner for loop 
        for (c = 0; c<= rows / 2; c++)   
        {  
            //To print the vertical lines 
            if ((c == 0 || c == rows / 2) && r != 0 ||  
            //Prints the first line 
            r == 0  && c != rows / 2 ||   
            //prints the middle line
            r == rows / 2)   
                System.out.print((char)(c+ascii));  
            else  
                System.out.print(" ");  
        }  
        //Prints new line
        System.out.println();  
        }  
    }  
}
Output:

Enter rows : 8

ABC 
A     D
A     D
ABCD
A     D
A     D
A     D

C Code to Print Alphabet A character Pattern

#include <stdio.h>
int main(int argc, char const *argv[])
{
    int ascii=65;
    int r, c, rows;
    //Taking row as input from user
    printf("Enter rows : ");
    scanf("%d", &rows);
    // Outer for loop
    for (r = 0; r <= rows; r++)
    {
        // Inner for loop
        for (c = 0; c <= rows / 2; c++)
        {
            //To print the vertical lines
            if ((c == 0 || c == rows / 2) && r != 0 ||
                //Prints the first line
                r == 0 && c != rows / 2 ||
                //prints the middle line
                r == rows / 2)
                printf("%c",(c+ascii));
            else
                printf(" ");
        }
        //Prints new line
        printf("\n");
    }
    return 0;
}
Output:

Enter rows : 8

ABC 
A     D
A     D
ABCD
A     D
A     D
A     D

C++ Code to Print Alphabet A character Pattern

#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    int ascii=65;
    int r, c, rows;
    //Taking row as input from user
    cout << "Enter rows : ";
    cin >> rows;
    // Outer for loop
    for (r = 0; r <= rows; r++)
    {
        // Inner for loop
        for (c = 0; c <= rows / 2; c++)
        {
            //To print the vertical lines
            if ((c == 0 || c == rows / 2) && r != 0 ||
                //Prints the first line
                r == 0 && c != rows / 2 ||
                //prints the middle line
                r == rows / 2)
                cout << (char)(c+ascii);
            else
                cout << " ";
        }
        //Prints new line
        cout << endl;
    }
    return 0;
}
Output:

Enter rows : 8

ABC 
A     D
A     D
ABCD
A     D
A     D
A     D

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

Printing Right Angled Triangle with Row wise Decreasing Character Pattern

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

Example-1

When character=h 
and row value=3

h
h g
h g f
Example-2:

When character=A 
and row value=5

Z
Z X
Z X W
Z X W V
Z X W V U

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 the character and store it in a variable c.
  • Then enter total row and store it in an integer variable row_count.
  • Take one outer for loop to iterate the rows.
  • Take one inner loop to iterate the columns and print the character.
  • After each iteration print a new line.

JAVA CODE:

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


Output:

Character : Z
Rows : 5

Z
Z X
Z X W
Z X W V
Z X W V U

C CODE:

#include <stdio.h>

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

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

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

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

Character : Z
Rows : 5

Z
Z X
Z X W
Z X W V
Z X W V U

C++ CODE:

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

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

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

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


Output:

Character : Z
Rows : 5

Z
Z X
Z X W
Z X W V
Z X W V U

Related Java Star Pattern Programs:

Java Program to Print Mirrored Right-Angled Triangle with Repeated Character (Decreasing Order) Pattern

Program to Print Mirrored Right-Angled Triangle with Repeated Character (Decreasing Order) Pattern

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

In this program we are going to see how to print a mirrored right-angled triangle character pattern in decreasing order.

Example-1

When character=p
and row value=4

       p
     oo
   nnn
mmm
Example-2:

When character=G 

and row value=5

          E
       DD
      CCC
    BBBB
 AAAAA

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 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 Mirrored Right-Angled 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, hold=row_count-1;
    //Converting the character to its ascii value
    int asciiValue = (int) c;

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

Output

Character : E
Rows : 5

         E
      DD
     CCC
   BBBB
AAAAA

C Code to Print Mirrored Right-Angled 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, hold = row_count - 1;
    //Converting the character to its ascii value
    int asciiValue = (int)c;

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

Character : E
Rows : 5

         E
      DD
     CCC
    BBBB
 AAAAA

C++ Code to Print Mirrored Right-Angled 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, hold = row_count - 1;
    //Converting the character to its ascii value
    int asciiValue = (int)c;

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

Output:

Character : E
Rows : 5

          E
       DD
     CCC
   BBBB
AAAAA

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

Program to Print Right Angled Triangle with Column Wise Increasing Character Pattern

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

Example-1

When character=h 
and row value=3

h
i k
j l m
Example-2:

When character=A 
and row value=5

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

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

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

Approach:

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

JAVA CODE:

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, charDif;
        //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++)
            {
            //Reseting the character difference and 
            //incrementing the character after each iteration
                charDif = row_count-1;
                asciiValue = c++;
                //Inner loop to iterate columns
                for(col = 0; col<row+1; col++)
                {
                    System.out.print((char)(asciiValue)+" ");
                    asciiValue+=charDif;
                    charDif--;
                }
                //Prints a newline
                System.out.println();
            }
        }
    }
}

Output:

Character : A
Rows : 5

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

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

Character : A
Rows : 5

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

C++ CODE:

#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    //Taking character to be printed as input from the user
    cout << "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, charDif;
    //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++)
        {
            //Reseting the character difference and 
            //incrementing the character after each iteration
            charDif = row_count - 1;
            asciiValue = c++;
            //Inner loop to iterate columns
            for (col = 0; col < row + 1; col++)
            {
                cout << (char)asciiValue << " ";
                asciiValue += charDif;
                charDif--;
            }
            //Prints a newline
            cout << endl;
        }
    }
    return 0;
}

Output:

Character : A
Rows : 5

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

Related Java Star Pattern Programs:

Java Program to Print Mirrored Right-Angled Triangle with Repeated Character (Increasing Order) Pattern

Program to Print Mirrored Right-Angled Triangle with Repeated Character (Increasing Order) Pattern

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

In this program we are going to see how to print a mirrored right-angled triangle character pattern.

Example-1:
When character=h
and row value =3
   h
  i i 
j j j
Example-2:

When character=A 
and row value=4

        A
      BB
    CCC
 DDDD

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 the character and store it in a variable c.
  • Then enter total row and store it in an integer variable row_count.
  • Take one outer for loop to iterate the rows.
  • Take one inner loop to iterate the columns and print the character.
  • After each iteration print a new line.

Java Code to Print Mirrored Right-Angled 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, hold=row_count-1;
        //Converting the character to its ascii value
        int asciiValue = (int) c;
    
        //Checks whether the character is a letter or not
        if(asciiValue>=65&&asciiValue<=122)
        {
            
            //Outer loop to iterate rows
            for (row = 1; row <= row_count; row++)
            {
                //Inner loop to print space
                for (col = 1; col <=hold; col++)
                {
                    System.out.print(" ");
                }
                hold--;
                //Inner loop to print character
                for(col = 1; col<=row; col++)
                {
                    System.out.print(c);
                    
                }
                c++;
                //Prints a newline
                System.out.println();
            }
        }
    }
}
Output:

Character : A
Rows : 4

       A
      BB
    CCC
 DDDD

C Code to Print Mirrored Right-Angled 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, hold = row_count - 1;
    //Converting the character to its ascii value
    int asciiValue = (int)c;

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

Character : A
Rows : 4

        A
       BB
     CCC
  DDDD

C++ Code to Print Mirrored Right-Angled 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, hold = row_count - 1;
    //Converting the character to its ascii value
    int asciiValue = (int)c;

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

Output:

Character : A
Rows : 4

        A
       BB
     CCC
  DDDD

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 Alphabet T Character Pattern

Program to Print Alphabet T Character Pattern

In the previous article, we have discussed Java Program to Print Digit 8 Character Pattern

In this article we are going to see how to print the alphabet ‘T’ character pattern.

Example:

When Size : 5

 AAAAAA
      B  
      C  
      D  
      E

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

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

Approach:

  • Enter the size and store it in an integer variable size.
  • Take first for loop to print all rows.
  • Take second/inner for loop to print column values.
  • Then go on printing the character symbols according to the iteration.

Java Code to Print Alphabet T Character Pattern

import java.util.Scanner;
class Main
{
    public static void main(String[] args)  
    {  
        //starting ascii value taken 65
        int ascii=65;
        int r, c;
        Scanner scan = new Scanner(System.in);
        System.out.print("Size : ");
        //Taking size as input from user
        int size=scan.nextInt();
        
        //Outer loop
        for(r = 0; r<size; r++)
        {   
            //Inner loop
            for(c = 0; c<size; c++)
            {
                //Condition to print star
                if(r==0||c==size/2)
                    System.out.print((char)(r+ascii));
                else
                    System.out.print(" ");
            }        //Prints a new line
            System.out.println();
        }
    }
}
Size : 5
AAAAAA
   B  
   C  
   D  
   E

C Code to Print Alphabet T Character Pattern

#include <stdio.h>
int main(int argc, char const *argv[])
{
    int ascii=65;
    int size, r, c;
    
    printf("Size : ");
    //Taking size as input from user
    scanf("%d", &size);
    for (r = 0; r < size; r++)
    { //Outer loop
        for (c = 0; c < size; c++)
        { //Inner loop
            if (r == 0 || c == size / 2)
                //Condition to print star
                printf("%c",(r+ascii));
            else
                printf(" ");
        }
        //Prints a new line
        printf("\n");
    }
    return 0;
}
Output:

Size : 5

AAAAAA
     B  
     C  
     D  
     E

C++ Code to Print Alphabet T Character Pattern

#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    //starting ascii value taken 65
    int ascii=65;
    cout << "Size : ";
    //Taking size as input from user
    int size, r, c, k;
    cin >> size;
    for (r = 0; r < size; r++)
    { //Outer loop
        for (c = 0; c < size; c++)
        { //Inner loop
            if (r == 0 || c == size / 2)
                //Condition to print star
                cout << (char)(r+ascii);
            else
                cout << " ";
        }
        //Prints a new line
        cout << endl;
    }
    return 0;
}
Output:

Size : 5

AAAAAA
     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 Inverted Right-Angled Triangle with Decreasing Character Pattern

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

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

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

Example-1

When character=h 
and row value=3

hgf
gf
f
Example-2:

When character=E 
and row value=5

EDCBA
DCBA
CBA
BA
A

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

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

Approach:

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

Java Code to Print Inverted Right-Angled Triangle with Decreasing Character Pattern

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

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

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

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

Character : E
Rows : 5

EDCBA
DCBA
CBA
BA
A

C Code to Print Inverted Right-Angled Triangle with Decreasing Character Pattern

#include <stdio.h>

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

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

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

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

Output:

Character : E
Rows : 5

EDCBA
DCBA
CBA
BA
A

C++ Code to Print Inverted Right-Angled Triangle with Decreasing Character Pattern

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

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

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

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

Output:

Character : E
Rows : 5

EDCBA
DCBA
CBA
BA
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: