Java面试题

1.关于1...n的全排列。比如:1,2,3的全排列为123,132,213,231,312,321

public class Test {
 public static void main(String[] args) throws Exception {
  String[] array = new String[] { "1", "2","3"};
  int length=array.length;
  listAll(Arrays.asList(array), "",length);
 }

 public static void listAll(List candidate, String prefix,int length) {
  if(prefix.length()==length)
   System.out.println(prefix);
  for (int i = 0; i < candidate.size(); i++) {
   List temp = new LinkedList(candidate);
   listAll(temp, prefix + temp.remove(i),length);
  }
 }
}

2.关于一个赋值顺序问题。

int a=0;

int[] b=new int[5];
int c=3;
b[a]=a=c;
b[3]的值为多少?

b[3]为0。

原文地址:https://www.cnblogs.com/hzcxy/p/2980876.html