Java Program to Print Plus Character Pattern

Printing Plus Character Pattern

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

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

Example:

When row value =5
         E 
         E 
         E 
ABCDEFGHI
         E 
         E 
         E 
         E

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 total row and store it in an integer variable say row.
  • Take an inner loop to print the column values.

Java Code to Print Plus Character Pattern

import java.util.Scanner;
public class Main
{
    public static void main(String[] args)
    {
    
    // starting ASCII value taken 64
    int ascii=64;
    
    Scanner sc=new Scanner(System.in);
    System.out.print("Enter row value = ");
    int row=sc.nextInt();
    // iterate through loop and print column values
    for(int r=1;r<=2*row-1;r++)
        {
            if(r!=row)
            // here the column values will be printed once
            for(int c=1;c<=row;c++)
            {   if(c==row)
                System.out.print((char)(c+ascii));
                System.out.print(" ");               
            }
            else
          // here the column values will be printed 2*row-1 times
            for(int c=1;c<=2*row-1;c++)
            {
            System.out.print((char)(c+ascii));
            }
        System.out.println();
        
        }
    }
}
Output:

Enter row value =     5
         E 
         E 
         E 
         E 
ABCDEFGHI
         E 
         E 
         E 
         E

C Code to Print Plus Character Pattern

#include <stdio.h>
int main()
{
    int row;
    int ascii=64;
    printf("Enter row value = ");
    scanf("%d",&row);
    for(int r=1;r<=row*2-1;r++)
        {
            if(r!=row)
            for(int c=1;c<=row;c++)
            {   if(c==row)
                printf("%c",(c+ascii));
                printf(" ");               
            }
            else
            for(int c=1;c<=row*2-1;c++)
            {
                printf("%c",(c+ascii));
            }
        printf("\n");
        
        }
        
}
Output:

Enter row value =  5
   
         E 
         E 
         E 
         E 
ABCDEFGHI
         E 
         E 
         E 
         E

C++ Code to Print Plus Character Pattern

#include<iostream>
using namespace std;
int main()
    {
    int row;
    int ascii=64;
    cout<<"Enter row value = ";
    cin>>row;
    for(int r=1;r<=row*2-1;r++)
        {
            if(r!=row)
            for(int c=1;c<=row;c++)
            {   if(c==row)
                cout<<(char)(c+ascii);
                cout<<" ";               
            }
            else
            for(int c=1;c<=row*2-1;c++)
            {
                cout<< (char)(c+ascii);
            }
        cout<<"\n";
        
        }
}
Output:

Enter row value =   5
         E 
         E 
         E 
         E 
ABCDEFGHI
         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:

Leave a Comment