对己经排好序的数字字符串,查找出不连续的。
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
String num = "3,6,7,8,9,10,11,12,14";
int mid = 0;
String[] zh = num.split(",");
if (Integer.parseInt(zh[0]) != 1) {
for (int n = 1; n < Integer.parseInt(zh[0]); n++) {
System.out.println("----" + n);
}
}
for (int i = 0; i < zh.length - 1; i++) {
if (Integer.parseInt(zh[i + 1]) - Integer.parseInt(zh[i]) != 1) {
for (int j = 1; j < Integer.parseInt(zh[i + 1]) - Integer.parseInt(zh[i]); j++) {
mid = Integer.parseInt(zh[i]) + j;
System.out.println("----" + mid);
}
}
}
}
}