62,623
社区成员
发帖
与我相关
我的任务
分享
List<Integer> LoopDo(List<Integer> intList,List<Integer> indexList) {
if (intList.size == 0) {
//伪代码
if indexList的所有元素的集合满足你的要求,输出你所有的元素。
return indexList;
}
for (int i=0; i<intList.get(0).intValue; i++) {
LoopDo(intList.subList(1,intList.size()),indexList.add(new Integer(i)));
}
}
调用方法
main(){
List<Integer> intList = 你的string中分割得到的list
List<Integer> indexList = new ArrayList<Integer>();
LoopDo(intList,indexList);
}
if(i>=loop[len-1]){
i=0;
} String a="1,2,2,3";
String[] arr = a.split(",");
int len = arr.length;
int[] loop = new int[arr.length];
int[] curr = new int[arr.length];
for(int i=0;i<loop.length;i++)
loop[i] = new Integer(arr[i]).intValue();
for(int i=0;curr[0]<loop[0];i++){
for(int j=0;j<loop.length;j++)
System.out.print(curr[j]+"\t");
System.out.println();
curr[len-1]++;
for(int j=len-1;j>0;j--){
if(curr[j]==loop[j]){
for(int k=j;k<len;k++)
curr[k]=0;
curr[j-1]++;
}
}
if(i>=loop[len-1]){
i=0;
}
}public static void main(String[] args) {
// TODO Auto-generated method stub
int[] a = {1,1,2,3};
execute(a,0);
}
public static void execute(int[] a,int index){
if (index >= a.length)
return;
for (int i = 0; i < a[index]; i++){
//some code here
execute(a,index + 1);
}
}public static void main(String[] args) {
// TODO Auto-generated method stub
int[] a = {1,1,2,3};
execute(a,0);
}
public static void execute(int[] a,int index){
if (index >= a.length)
return;
for (int i = 0; i < a[index]; i++){
//some code here
execute(a,index + 1);
}
}
package com.capinfo.test;
public class StringTest {
public static void main(String[] args) {
String s="100,200,1000,9,2000";
digui(s);
}
/**
* @param s
* @author sundful
* @vesion 1.0
*/
public static void digui(String s)
{
String s1="";
String s2="";
if("".equals(s) || s.trim().length()<0) return;
int num=s.indexOf(",");
if(num !=-1)
{
s1=s.substring(0,num);
s2=s.substring(num+1);
for(int i=0;i<Integer.parseInt(s1);i++)
{
digui(s2);
System.out.println(i);
}
}
}
}