编写输出8位数,前面6位为0到9的全部组合,后面两位为A到E的全部组合??求用JAVA编写
1个回答
展开全部
import java.util.Arrays;
import java.util.LinkedList;
public class 带罩戚HtmlDemo
{
public static void recursionSub ( LinkedList<String[]> list, int count, String[] array, int ind, int 闷碰start,
int... indexs )
{
start++;
if (start > count - 1)
{
return;
}
if (start == 0)
{
indexs = new int[array.length];
}
for ( indexs[start] = ind; indexs[start] < array.length; indexs[start]++ )
{
recursionSub (list, count, array, indexs[start] + 1, start, indexs);
if (start == count - 1)
{
String[] temp = new String[count];
for ( int i = count - 1; i >= 0; i-- )
{
temp[start - i] = array[indexs[start - i]];
}
list.add (temp);
}
}
}
public static void main ( String[] args )
{
String string = "0,1,2,3,4,5,6,7,8,9";
String str2 = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
String[] A = string.split (",");
LinkedList<String[]> list1 = new LinkedList<String[]> ();
recursionSub (list1, 6, A, 0, -1);
A = str2.split (",");
LinkedList<String[]> list2 = new LinkedList<String[]> ();
recursionSub (list2, 2, A, 0, -1);
String reg = "[\\[\\]\\,\\s]";
for ( int 蠢陵i = 0; i < list1.size (); i++ )
{
String[] t1 = list1.get (i);
String prev = Arrays.toString (t1).replaceAll (reg, "");
for ( int k = 0; k < list2.size (); k++ )
{
String[] t2 = list2.get (k);
String next = Arrays.toString (t2).replaceAll (reg, "");
System.out.println (prev + next);
}
}
}
}
追问
真的很谢谢你,昨天面试,面试官出了这一题,说,能写正确就留下,写不出来就走人,当时就泪奔了,面试官说我思路不对!!
追答
面试什么具体什么职位的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询