Here's what ive got so far, but obviously i am not to good with grasping the concept of recursion at al, i think i need to completely start over
import javax.swing.JOptionPane;
import java.util.Random;
public class backpack{
int itemCount;
int maxWeight;
public static void main(
String[] args){
int[] packItems = new int[5];
double x;
int n;
Random myRandom = new Random();
// make the array!
for (int i = 0; i < 5; i++) {
packItems[i] = 0;
}
for (long i=0; i < 20; i++) {
// generate a new random number between 0 and 9
x = myRandom.nextDouble() * 10.0;
n = (int) x;
packItems[n]++;
}
public int testWeight(){
if((packItems[itemCount]+packItems[itemCount-1]+packItems[itemCount+1]) == 20){
System.out.println("The Combination is:" + packItems[itemCount]);
}
else
{
itemCount ++;
return testWeight();
}
}
}
}