这是我到目前为止编写的代码,用于查找整数的唯一组合。我收到了总整数的数量和将要创建的团队的长度,我想使用递归来找到所有组合
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class PartA {
public static void main(String[] args) {
Scanner sizeInput= new Scanner(System.in);
ArrayList<Integer> teams= new ArrayList<Integer>();
int groupSize=0;
int teamSize=0;
System.out.println("Type the size you wish the main group to be: ");
groupSize= sizeInput.nextInt();
System.out.println(" The group will be of size : "+groupSize);
System.out.println("Type the size the team will have: ");
teamSize= sizeInput.nextInt();
System.out.println(" The team will be of size : "+teamSize);
ArrayList<Integer> mainGroup= new ArrayList<Integer>();
for(Integer i=0;i<groupSize;i++){
mainGroup.add(i);
int loopTimes=mainGroup.size();
int count=0;
showTeams(mainGroup,teams,loopTimes,count,teamSize,groupSize);
}
}
public static Integer showTeams(ArrayList<Integer>mainGroup,
ArrayList<Integer>teams,int loopTimes,int count,
int teamSize,int groupSize) {
int e=0;
int i=0,o;
//int count=0;
//int loop=U.length();
while(count<=2){
for(i=0; i<loopTimes-1 ; i++){
o=i+count;
e=mainGroup.get(i)+mainGroup.get(o+1);
System.out.println(e);
}
count++;
loopTimes--;
System.out.println(count + " " + loopTimes);
if(count>loopTimes) {
System.out.println("Solution Found");
return e;
}
else
{ System.out.println("Recursion Call");
showTeams(mainGroup,teams,loopTimes,count,teamSize,groupSize);
}
}
return e;
}
}
我想要的只是打印整数的唯一组合