I am looking to come up with the following pattern of string subsequences:
# input - ALEX
# 1 - A, L, E, X
# 2 - AL, AE, AX, LE, LX, EX
# 3 - ALE, ALX, AEX, LEX
# 4 - ALEX
I wrote this, it comes up with most, but I am missing "LX","AE","ALX" and "AEX". Can I get those without adding a third loop?
public class StringPermutations {
public void stringPermutations(String input) {
for(int i = 0; i<input.length();i++){
for(int j = i; j<input.length(); j++){
String s = input.substring(i,j+1);
System.out.println(s);
}
}
}
public static void main(String[] args) {
new StringPermutations().stringPermutations("ALEX");
}
}