code running fine in Netbeans IDE
But showing nullPointerException here at line: if(str.length() == 0);
CODE:
import java.util.;
import java.io.;
public class Main {
public static void main(String args[]) throws IOException {
Scanner sc = new Scanner(System.in);
int n = 0;
if(sc.hasNextInt())
n = sc.nextInt();
while(n != 0) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
ArrayList<String> ans = getSS(str);
for(int i = 0; i < ans.size(); i++) {
System.out.println(ans.get(i));
}
n--;
}
}
public static ArrayList<String> getSS(String str) {
if(str.length() == 0) {
ArrayList<String> br = new ArrayList<>();
br.add("");
return br;
}
char cc = str.charAt(0);
String ros = str.substring(1);
ArrayList<String> mr = new ArrayList<>();
ArrayList<String> rr = getSS(ros);
for(int i = 0; i < rr.size(); i++) {
mr.add(rr.get(i));
mr.add(cc + rr.get(i));
}
return mr;
}
}