字符串 abcd
要求输出组合为 a ab abc abcd b bc bcd c cd d
能有不连续的情况出现 如何解决
字符串 abcd
要求输出组合为 a ab abc abcd b bc bcd c cd d
能有不连续的情况出现 如何解决
public class Main {
public static void main(String[] args) {
test("abcd");
}
public static void test(String str){
char[] array = str.toCharArray();
for (int i = 0; i < array.length; i++) {
System.out.println(array[i]);
String temp = String.valueOf(array[i]);
for (int j = i + 1; j < array.length; j++) {
temp = temp + String.valueOf(array[j]);
System.out.println(temp);
}
}
}
}