日期:2014-05-20 浏览次数:20724 次
public class ReaderTest {
private static final char[] bits = new char[24];
static{
bits[0] = '0';
int index = 1;
for(int i = 0; i < 26; i ++){
char c = (char) ('A' + i);
if(c != 'I' && c != 'O' && c != 'X')
bits[index ++] = c;
}
}
private static String increase(String str){
char[] charArray = str.toCharArray();
for(int i = 0; i < charArray.length; i ++){
int posInArray = charArray.length - 1 - i;
int pos = getPosInBits(charArray[posInArray]);
if(pos + 1 >= bits.length)
charArray[posInArray] = '0';
else{
charArray[posInArray] = bits[pos + 1];
break;
}
}
return new String(charArray);
}
private static int getPosInBits(char c){
for(int i = 0; i < bits.length; i ++){
if(bits[i] == c)
return i;
}
return -1;
}
public static void main(String[] args) throws IOException {
for(int i = 0; i < 100; i ++){
char[] randomChar = new char[4];
for(int j = 0; j < randomChar.length; j ++)
randomChar[j] = bits[(int) (Math.random() * bits.length)];
String targetString = new String(randomChar);
System.out.println("[" + targetString + "] increate 1 to :[" + increase(targetString)+ "]");
}
}
}