Pattern Program using 2D Array in JAVA

Pattern Program #2 using Array in Java

Question : Write a program to print the following pattern.






Program to print the above pattern :-

Program :-

import java.io.*;
import java.util.*;
class Pattern
{
    public static void main(String args[])
    {
        Scanner in = new Scanner(System.in);
        int i,j,k=1,n;
        System.out.println("Enter Number of Rows");
        n= in.nextInt();
        int ar[][]=new int[n][n];
        for(j=n-1;j>=0;j--) //Storing Elements
        {
            for(i=n-1;i>=j;i--)
            {
                ar[i][j]=k;
                k++;
            }
        }
        for(i=0;i<n;i++) //Printing Pattern
        {
            for(j=0;j<=i;j++)
            {
                System.out.print(ar[i][j]+"\t");
            }
            System.out.println();
        }
    }//end of main method
}//end of class


For Proper Understanding Watch the Video :-


All the best :)
Keep Learning :)

Comments

Popular posts from this blog

Frequency of each digit of a number in Java

Trimorphic Number in JAVA

Tri-Automorphic Number in JAVA