生成固定位数的字母流水号? 生成固定位数的字母流水号? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 类似这样的AAAAAAABAAAC.... public class Test { public static void main(String[] args) { IdentifierAlpha id = new IdentifierAlpha(4, 'A', 'Z'); for (int i = 0; i < 17575; i++) { id.next(); } // 应该输出 AZZZ System.out.println(id.next()); // 应该输出 BAAA System.out.println(id.next()); }}class IdentifierAlpha { private char[] sequence; private char start; private char end; private IdentifierAlpha() { } public IdentifierAlpha(int bit, char start, char end) { if(start > end) { char tmp = end; end = start; start = tmp; } this.start = start; this.end = end; sequence = new char[bit + 1]; sequence[sequence.length - 1] = (char) (start - 1); for (int i = sequence.length - 2; i > 0; i--) { sequence[i] = start; } sequence[0] = '_'; } /** * 每次增加一个字母,并且循环使用,如 ZZZZ,下一个则为 AAAA * @return */ public String next() { if (sequence == null) { return null; } sequence[sequence.length - 1] += 1; for (int i = sequence.length - 1; i > 0; i--) { if (sequence[i] > end) { sequence[i] = start; sequence[i - 1] = (i != 1) ? (char)(sequence[i - 1] + 1) : '_'; } else { break; } } return new String(sequence, 1, sequence.length - 1); }} 写一下我自己写的,对比一下上面的,自己的好像比较有局限性。谢谢:bao110908(长牙了,好痛) char changeChar ='A';int charint = 0;String nowFeeCode = "ZEYJDO"; char tempChar = '0'; charint = (int)changeChar; for(int count =0;count < nowFeeCode.length(); count++){ changeChar = nowFeeCode.charAt(count); charint = (int)changeChar; if (charint<=89){ tempChar = (char)(charint+1); nowFeeCode = nowFeeCode.substring(0,count) + tempChar + nowFeeCode.substring(count+1); tempChar = '0'; } else{ tempChar = 'A'; nowFeeCode = nowFeeCode.substring(0,count) + tempChar + nowFeeCode.substring(count+1); } if (tempChar == '0'){ break; } } System.out.println("Loop nowFeeCode = " + nowFeeCode); amr格式如何转mp3格式 能帮我看下这个代码怎么会报错的吗,谢谢 Hibernate中怎么样设置池连发呆数? 求助jacob的各个方法含义,拜先:( 纠错,求解! 请问多重try catch块和嵌套try catch块的区别是什么? 毕业设计不懂,请教大家 源代码阅读 什么时候用==,什么时候用equals ?? 心情极其不爽,散分了,开心一下 如何把字符串中的回车符去除掉? 一个字符串处理的问题,谢谢大家
AAAA
AAAB
AAAC
....
IdentifierAlpha id = new IdentifierAlpha(4, 'A', 'Z');
for (int i = 0; i < 17575; i++) {
id.next();
}
// 应该输出 AZZZ
System.out.println(id.next());
// 应该输出 BAAA
System.out.println(id.next());
}
}class IdentifierAlpha { private char[] sequence;
private char start;
private char end; private IdentifierAlpha() {
} public IdentifierAlpha(int bit, char start, char end) {
if(start > end) {
char tmp = end;
end = start;
start = tmp;
}
this.start = start;
this.end = end;
sequence = new char[bit + 1];
sequence[sequence.length - 1] = (char) (start - 1);
for (int i = sequence.length - 2; i > 0; i--) {
sequence[i] = start;
}
sequence[0] = '_';
} /**
* 每次增加一个字母,并且循环使用,如 ZZZZ,下一个则为 AAAA
* @return
*/
public String next() {
if (sequence == null) {
return null;
}
sequence[sequence.length - 1] += 1;
for (int i = sequence.length - 1; i > 0; i--) {
if (sequence[i] > end) {
sequence[i] = start;
sequence[i - 1] = (i != 1) ? (char)(sequence[i - 1] + 1) : '_';
} else {
break;
}
}
return new String(sequence, 1, sequence.length - 1);
}
}
谢谢:bao110908(长牙了,好痛) char changeChar ='A';
int charint = 0;
String nowFeeCode = "ZEYJDO";
char tempChar = '0';
charint = (int)changeChar;
for(int count =0;count < nowFeeCode.length(); count++){
changeChar = nowFeeCode.charAt(count);
charint = (int)changeChar;
if (charint<=89){
tempChar = (char)(charint+1);
nowFeeCode = nowFeeCode.substring(0,count) + tempChar + nowFeeCode.substring(count+1);
tempChar = '0';
}
else{
tempChar = 'A';
nowFeeCode = nowFeeCode.substring(0,count) + tempChar + nowFeeCode.substring(count+1);
}
if (tempChar == '0'){
break;
}
}
System.out.println("Loop nowFeeCode = " + nowFeeCode);