From ed93234f062706ad14aa0a3a0fa60b7e37cd58ad Mon Sep 17 00:00:00 2001 From: ragu-1997 <81232337+ragu-1997@users.noreply.github.com> Date: Mon, 31 Oct 2022 12:27:35 +0530 Subject: [PATCH] Create Bell Numbers.java --- Dynamic_program/Java/Bell Numbers.java | 32 ++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Dynamic_program/Java/Bell Numbers.java diff --git a/Dynamic_program/Java/Bell Numbers.java b/Dynamic_program/Java/Bell Numbers.java new file mode 100644 index 0000000..fe4764e --- /dev/null +++ b/Dynamic_program/Java/Bell Numbers.java @@ -0,0 +1,32 @@ +/*package whatever //do not write package name here */ +// Java program to find number of ways of partitioning it. + +import java.io.*; +// "static void main" must be defined in a public class. +public class GFG { + public static void main(String[] args) + { + int n = 5; + int[][] s = new int[n + 1][n + 1]; + for (int i = 0; i < n + 1; i++) { + for (int j = 0; j < n + 1; j++) { + if (j > i) + s[i][j] = 0; + else if (i == j) + s[i][j] = 1; + else if (i == 0 || j == 0) + s[i][j] = 0; + else { + s[i][j] + = j * s[i - 1][j] + s[i - 1][j - 1]; + } + } + } + int ans = 0; + for (int i = 0; i < n + 1; i++) { + ans += s[n][i]; + } + System.out.println(ans); + } +} +