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: