用一串字符串,有字母和数字,算出一列只有数字的序列号,有什么好的算法吗
解决方案 »
- 如何调用数组函数(也就是把 public int[] 函数名() 这个数组放到其它类的函数中作为整型数组变量使用)?
- 乘法口诀
- Thinking in java第1版里1段程序的问题
- 弹出式菜单怎么就不能实现啊
- how to read word from console
- 我在做文件操作的题(老师布置的)
- 请问如何将字节流转换为Blob?(100)
- jdk1.3下用java解释java应用程序就出现异常java.lang.NoClassDefFoundError
- JAVA数据加密,大撒分。。。。
- How to generate PDF file using a templet in JAVA (I'm sory my computer can not input Chinese.)
- java的具体环境配置如何
- 请问哪儿可以找到ibm jdk 1.3.1 for windows啊?
public class SerialNumber { public static long getSerialNum(String str){
if (str == null){
return 0;
}
byte[] bt = str.getBytes();
int leng = bt.length;
long sn = 0;
for(int i = 0; i < leng; i++){
sn += bt[i] * getPowerNum(leng - i - 1);
}
return sn;
}
private static long getPowerNum(int n){
long num = 1;
for(int i = 0; i < n; i++){
num *= 10;
}
return num;
}
public static void main(String[] args){
System.out.println(getSerialNum("qw12"));
}
}
谁有做过这个的,共享一下吧