Я хочу найти все подмножества набора Рекурсивно, и вот код, который у меня есть.Моя проблема с этой частью:
char[] set = in.nextLine().toCharArray().split("(?!^)");
когда я запускаю этот код, я получаю эту ошибку, и я не знаю, как ее решить.
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Cannot invoke split(String) on the array type char[]
at subsetGeek.Main.main(Main.java:35)
Я хочу взять Setот пользователя с этой частью кода, положить его в символ [] и затем показать подмножества.
// A Java program to print all subsets of a set
import java.io.IOException;
import java.util.Scanner;
class Main
{
// Print all subsets of given set[]
static void printSubsets(char set[])
{
int n = set.length;
// Run a loop for printing all 2^n
// subsets one by obe
for (int i = 0; i < (1<<n); i++)
{
System.out.print("{ ");
// Print current subset
for (int j = 0; j < n; j++)
// (1<<j) is a number with jth bit 1
// so when we 'and' them with the
// subset number we get which numbers
// are present in the subset and which
// are not
if ((i & (1 << j)) > 0)
System.out.print(set[j] + " ");
System.out.println("}");
}
}
// Driver code
public static void main(String[] args)
{ Scanner in = new Scanner(System.in);
char[] set = in.nextLine().toCharArray().split("(?!^)");
//char set[] = {'a', 'b', 'c'};
printSubsets(set);
}
}
Есть ли что-нибудь еще, что может быть заменено этой частью моего кода?