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);
}
}
相关文档:
事务处理总结
来源:http://space.itpub.net/13956325/viewspace-598381
一、什么是Java 事务
通常的观念认为,事务仅与数据库 相关。
事 务必须服从ISO/IEC所制定的ACID原则。ACID是原子性(atomicity)、一致性(consistency)、隔离性 (isolation)和持久性(durability)的缩写。事务的原子性表示事务 ......
public class TestClass{
public static void main(String args[]){
VarArgs(1, "one");
VarArgs(2, "one", "two");
VarArgs(3, "one", "two", "three");
VarArgs(0); // Attention!
}
static void VarArgs(int nRequired, String... trailing){
System.out.print("Required: " + nRequired + " ");
......
前一段时间因为需要帮别人写了简单的字符串分隔的java小程序,尽管最后没用上,但是作为练习还是不错的。
需求:对于像如下的字符创将其分隔为两列,这样就可以直接粘贴的Excel中各自列,否则一个一个分隔会耗费很多时间。
16 bit microcomputer 16 位微型计算机
3 d distribution 三维分布
4 ......
因为工作需要,需要在同一时间执行多次某个操作,看看是否会引起数据的deadlock文件。
多线程具体执行类
package com.ericyang.test.cmdline;
import java.util.List;
import java.text.SimpleDateFormat;
import java.text.DateFormat;
import java.util.Date;
class ThreadClass extends xxxTestBase implemen ......
package cn.com.view.read;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class ReadExcel {
......