//Only the solution of the third problem is posted since //the remainign two problems were very easy. //This third problem is along the lines of //one of the partition problem discused in the practice problems //recursion. //Try to understand it. The code is self explanatory if you have //seen the solution of the corresponding practice poroblem. class partition { public static void Partition_b_S(int n, int i, int k, String S) { if(n==0) System.out.println("{"+S+"}"); else { Partition_b_S(0,n,k,S+","+n); for(int j = i+k; n-2*j>=k; j=j+1) Partition_b_S(n-j,j,k,S+","+j); } } public static void main(String args[]) { int n = Integer.parseInt(args[0]); int k = Integer.parseInt(args[1]); System.out.print("All possible sets with sum ="+n); System.out.println(" and difference at least "+k+" are: "); System.out.println("{"+n+"}"); for(int i = 1;n-2*i>=k;i=i+1) Partition_b_S(n-i,i,k,i+""); } }