/* DATE:3/11/2008 AUTHOR: M DEEPAK MAIL BUGS TO:mdeepak@cse.iitk.ac.in */ /* 2. Stirling numbers: A stirling number of the first kind is defined as follows s(n,0) = 0, for all n > 0 s(n+1,k) = s(n,k-1) - n*s(n,k), for all n >= 0 and k>0. s(0,0) = 1 Write a recursive method to compute stirling number of first kind. Use it in a program which reads integers n and k from command line and print the corresponding stirling number. */ class Stirling{ public static void main(String args[]){ int n=0; int k=0; try{ n=Integer.parseInt(args[0]); k=Integer.parseInt(args[1]); }catch(Exception e){ System.out.println("Please Enter two numbers as argument"); System.exit(0); } System.out.println("The numbers entered are n="+n+",k="+k); System.out.println("Stirling number for First kind="+stirling(n,k)); } public static int stirling(int n,int k){ if((n==0)&&(k==0)) return 1; else if((n>=1)&&(k>0)) return stirling(n-1,k-1)-(n-1)*stirling(n-1,k); else if(n>0) return 0; return 0; } }