package reverse;
public class Cat {
public static void main(String[] args) {
int[] s = {4, 2, 1, 3, 0, 5};
String tmp = "";
for(int i=1;i<s.length-1;i++){
tmp = tmp + s[i];
}
String str = tmp;
int length = 2;
printAll(str, length, "");
System.out.println(ss);
}
private static String ss = "";
private static void printAll(String number, int length, String s2) {
if(s2.length() == length){
ss = ss + s2 + ",";
System.out.println(s2 + " ");
}else{
for(int i = 0;i < number.length(); i++){
System.out.println(new StringBuffer(number).substring(i+1).toString());
System.out.println(length);
System.out.println(s2 + number.charAt(i));
printAll(new StringBuffer(number).substring(i+1).toString(), length, s2 + number.charAt(i));
}
}
}
}
public class Cat {
public static void main(String[] args) {
int[] s = {4, 2, 1, 3, 0, 5};
String tmp = "";
for(int i=1;i<s.length-1;i++){
tmp = tmp + s[i];
}
String str = tmp;
int length = 2;
printAll(str, length, "");
System.out.println(ss);
}
private static String ss = "";
private static void printAll(String number, int length, String s2) {
if(s2.length() == length){
ss = ss + s2 + ",";
System.out.println(s2 + " ");
}else{
for(int i = 0;i < number.length(); i++){
System.out.println(new StringBuffer(number).substring(i+1).toString());
System.out.println(length);
System.out.println(s2 + number.charAt(i));
printAll(new StringBuffer(number).substring(i+1).toString(), length, s2 + number.charAt(i));
}
}
}
}
这是一个使用Java解决数学中组合问题的示例,通过遍历和递归方法,找出给定数组s中所有可能的长度为2的子集组合。程序首先遍历数组,然后通过递归调用printAll方法打印所有可能的组合。

1万+

被折叠的 条评论
为什么被折叠?



