这期内容当中小编将会给大家带来有关怎么进行JAVA-EAN-13校验位计算,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
/**
* EAN-13校验位计算
*
* @param barcode
* @return
*/
private static int BarcodeJiaoYan(String barcode) {
if (barcode.length() != 12)
return -1;
int s1 = 0;
int s2 = 0;
for (int i = 1; i <= 12; i++) {
if (i % 2 == 1) {
s1 = s1 + Integer.parseInt(barcode.substring(i - 1, i));// 奇数
} else {
s2 = s2 + Integer.parseInt(barcode.substring(i - 1, i));// 偶数
}
}
s2 = s2 * 3;
int c = 10 - (s1 + s2) % 10;
return c == 10 ? 0 : c;
}
上述就是小编为大家分享的怎么进行JAVA-EAN-13校验位计算了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注天达云行业资讯频道。