Java程序,一个实现Enumeration的组合类
import java.util.Enumeration;
public class CipherTest implements Enumeration {
private int N;
private int c[], k;
private Object[] objs;
public CipherTest(Object[] items) {
N = items.length;
c = new int[N + 1];
for (int i = 0; i <= N; i++)
c[i] = i;
objs = items;
k = 1;
}
public boolean hasMoreElements() {
return (k < N);
}
public Object nextElement() {
int i = 0;
if ((k & 1) != 0)
i = c[k];
Object tmp = objs[k];
objs[k] = objs[i];
objs[i] = tmp;
k = 1;
while (c[k] == 0)
c[k] = k++;
c[k]--;
return objs;
}
public static void main(String[] args) {
// String[] strs = { "1", "2", "3", "4" };
Integer[] nums = new Integer[6];
for (int i = 0; i < nums.length; i++)
nums[i] = i + 1;
System.out.println("N=" + nums.length);
Enumeration e = new CipherTest(nums);
int count = 0;
while (e.hasMoreElements()) {
Object[] a = (Object[]) e.nextElement();
if (((Integer) a[0]).intValue() != 4)
continue;
boolean isContinue = false;
for (int i = 0; i < a.length - 1; i++) {
if ((((Integer) a[i]).intValue() == 2 && ((Integer) a[i + 1])
.intValue() == 3)
|| (((Integer) a[i]).intValue() == 3 && ((Integer) a[i + 1])
.intValue() == 2)) {
isContinue = true;
break;
}
}
if (isContinue)
continue;
System.out.print("{" + a[0]);
for (int i = 1; i < a.length; i++)
System.out.print(", " + a[i]);
System.out.println("}");
count++;
}
System.out.println("count=" + count);
}
}
相关文档:
在java中,假设你有一个user 对象的list,此user对象封装了用户的id, first name, last name and age. 然后你想调用一个web service(eg. UserService.deleteUsersByIds(List<Integer> userIds) 去删除数据库中指定的这些user。 听起来似乎不太困难,不是么? 你所需要只是将 List<User> 转化成List&l ......
public class bubblesort {
public static void main(String[] args) {
int array[]=new int[]{1,5,9,4,6,2};
int m;
for(int i=0;i<array.length;i++){
System.out.print(arra ......
转另一个论坛的帖子:
迅雷面试回来,用了整整一下午(不知道怎么说了,其中等待时间都快2小时了),自己感觉笔试和上机还可以,但技术面谈这一关答得不太好,现在再次感觉互联网公司与一般软件公司的区别了,其中一点就是互联网应用在性能上要求很高,谈了一个小时大部分题目感觉都在谈论性能问题,自己在方面一直是弱项 ......
要使用dom4j读写XML文档,需要先下载dom4j包,dom4j官方网站在 http://www.dom4j.org/
目前最新dom4j包下载地址: http://nchc.dl.sourceforge.net/sourceforge/dom4j/dom4j-1.6.1.zip
解开后有两个包,仅操作XML文档的话把dom4j-1.6.1.jar加入工程就可以了,如果需要使用XPath的话还需要加入包jaxen-1.1-beta-7.jar.
以下 ......