/**
* Created by XJTUSE-PC on 2016/10/18.
*/
public class Combination
{
public static void main(String[] args)
{
char[] ch = {'a', 'b', 'c', 'd'};
boolean[] bool = new boolean[ch.length];
combinat(ch, 2, bool, 0);
}
//num:去几个元素,start:开始位置,bool:标记是否取出
public static void combinat(char[] ch, int num, boolean[] bool, int start)
{
if(num == 0)
{
for(int i = 0; i < start; i ++)
{
if(bool[i] == true)
{
System.out.print(ch[i]);
}
}
System.out.println();
return;
}
if(start == ch.length)
{
return;
}
bool[start] = true;
combinat(ch, num - 1, bool, start + 1);
bool[start] = false;
combinat(ch, num, bool, start + 1);
}
}
* Created by XJTUSE-PC on 2016/10/18.
*/
public class Combination
{
public static void main(String[] args)
{
char[] ch = {'a', 'b', 'c', 'd'};
boolean[] bool = new boolean[ch.length];
combinat(ch, 2, bool, 0);
}
//num:去几个元素,start:开始位置,bool:标记是否取出
public static void combinat(char[] ch, int num, boolean[] bool, int start)
{
if(num == 0)
{
for(int i = 0; i < start; i ++)
{
if(bool[i] == true)
{
System.out.print(ch[i]);
}
}
System.out.println();
return;
}
if(start == ch.length)
{
return;
}
bool[start] = true;
combinat(ch, num - 1, bool, start + 1);
bool[start] = false;
combinat(ch, num, bool, start + 1);
}
}