class knapsack{
static int[] a=new int[5];
public static void main(String[] args){
System.out.println("Welcome to Knapsack Program");
a[0]=11;
a[1]=8;
a[2]=7;
a[3]=4;
a[4]=3;
knp(a,20,0);
}
public static void knp(int a[],int w,int y){
System.out.println("for idex :"+y);
System.out.println(".............");
if(y<5){
for(int i=y+1;i<5;i++){
if(a[y]+a[i]<w){
int w1=a[y]+a[i];
if((w-w1)<=a[4]){
for(int j=i+1;j<5;j++){
if(w1+a[j]<w){
System.out.println(a[y]+","+a[i]+","+a[j]+", weight="+(a[y]+a[i]+a[j]));
}
}
}
else{
System.out.println(a[y]+","+a[i]+", weight="+(a[y]+a[i]));
}
}
}
knp(a,w,++y);
}
}
}
Leave Your Comments here !!!