I am completing a lab assignment and get this error when I compile. The program runs fine, bit would like to fix what is causing the error. The program code and the complete error is below. Thanks as always!
import java.util.HashSet;
import java.util.Scanner;
public class Problema4 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n,s;
while(scan.hasNext()){
n=scan.nextInt();
s=scan.nextInt();
int A[] = new int[n];
for (int i =0; i < n; i++) {
A[i] =scan.nextInt();
}
find(A, s);
}
}
public static void find(int[] A, int sum) {
int[] solution = new int[A.length];
HashSet<String> conjuntos = new HashSet(); // usamos la estructura HashSet para que los subconjuntos no se repitan
find(A, 0, 0, sum, solution, conjuntos);
System.out.println(conjuntos.size());
}
public static void find(int[] A, int currSum, int index, int sum, int[] solution, HashSet<String> conjuntos) {
if (currSum == sum) {
String subConjunto = "";
for (int i = 0; i < solution.length; i++) {
if (solution[i] == 1) {
subConjunto += " " + A[i];
}
}
if (!subConjunto.trim().isEmpty()) {
conjuntos.add(subConjunto);
}
}
if (index == A.length) {
return;
} else {
solution[index] = 1; // selecionamos el elemento
currSum += A[index];
find(A, currSum, index + 1, sum, solution, conjuntos);
currSum -= A[index];
solution[index] = 0; // no seleccionamos el elemento
find(A, currSum, index + 1, sum, solution, conjuntos);
}
return;
}
}