Bell Number Triangle Pattern

Bell Number Triangle Pattern in Java

Question : Write a program to print the following pattern.



Bell Number Triangle Pattern


Program to print the above pattern :-

Program :-

import java.io.*;
import java.util.*;
class Pat2
{
    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(); //input number of rows of pattern
        int ar[][]=new int[n][n]; //2D array for storing number
        ar[0][0]=1;
        for(i=1;i<n;i++)
        {
            ar[i][0] = ar[i-1][i-1];
            for(j=1;j<=i;j++)
            {
                ar[i][j]= ar[i-1][j-1] + ar[i][j-1];
            }
        }
        for(i=0;i<n;i++)
        {
            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 :-





Watch this video : Bell Triangle Pattern in Java

All the best :)
Keep Learning :)

Comments

Popular posts from this blog

Frequency of each digit of a number in Java

Trimorphic Number in JAVA

PalPrime Number in JAVA