/** * 上送终端编号的后两位生成规则 总共可以生成 (36*36-1)1295个编号 * 01...09 0A...0Z * 10...19 1A...1Z * ............... * A0...A9 AA...AZ * ............... * Z0...Z9 ZA...ZZ */ public String generateNumber(String number){ String ret=number.substring(0,number.length()-2); //取前半部分 number=number.substring(number.length()-2); //取最后两位 // 取第一个字符 char ch1=number.charAt(0); char ch2=number.charAt(1); //生成第二个字符串 if(number.equals("ZZ")){ //达到上限 ZZ,不使用生成规则生成 return null; } if(ch2<‘Z‘){ //因为9的下一个字母是A if(ch2==‘9‘){ ch2=‘A‘; }else{ ch2+=1; } ret=ret+""+ch1+ch2; }else{ //第一个字符加1;第二个字符为0 if(ch1==‘9‘){ ch1=‘A‘; }else{ ch1+=1; } ret=ret+""+ch1+0; } return ret; }
public static void main(String[] args){ String[] arr={"01","09","0A","0Y","0Z","90","99","9B","9Z","A0","AZ","Z0","ZY","ZZ"}; for(String arr1:arr){ System.out.println("--->:"+test(arr1)); } }
时间: 2024-11-10 00:19:04