Java Program to Print Plus Number Pattern

Program to Print Plus Number Pattern

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

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

Example:

Enter row value =  5
        1 
        2 
        3 
        4 
555555555
        6 
        7 
        8 
        9

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 say row.
  • Take an inner loop to print the column values.

Java Code to Print Plus Number Pattern

import java.util.Scanner;
public class Main
{
    public static void main(String[] args)
    {
             
    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(r);
                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(r);
            }
        System.out.println();
        
        }
    }
}
Output:

Enter row value =   5
      
        1 
        2 
        3 
        4 
555555555
        6 
        7 
        8 
        9

C Code to Print Plus Number Pattern

#include <stdio.h>
int main()
{
    int row;
    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("%d",r);
                printf(" ");               
            }
            else
            for(int c=1;c<=row*2-1;c++)
            {
                printf("%d",r);
            }
        printf("\n");
        
        }
        
}
Enter row value =  5

        1 
        2 
        3 
        4 
555555555
        6 
        7 
        8 
        9

C++ Code to Print Plus Number Pattern

#include<iostream>
using namespace std;
int main()
    {
    int row;
    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<<r;
                cout<<" ";               
            }
            else
            for(int c=1;c<=row*2-1;c++)
            {
                cout<<r;
            }
        cout<<"\n";
        
        }
}
Output:

Enter row value =  5

        1 
        2 
        3 
        4 
555555555
        6 
        7 
        8 
        9

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 Number Pattern Programs: