Java基础-条形码校验

Java基础-条形码校验_第1张图片

public class StringStr {


public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
String a = cin.nextLine();
   int[] b = new int[a.length()];
for(int i = 0; i < a.length(); i++){
b[i] = Integer.valueOf(a.substring(i,i+1));
}
int sum1 = 0;
int sum2 = 0;
for(int i = 0; i < b.length - 1; i = i + 2){
sum1 = sum1 + b[i];
sum2 = sum2 + b[i+1];
}
int temp = sum1 + sum2 * 3;
int g = temp%100%10;  //取的个位
int y = 0;
if(g==0){
y = 0;
}else{
y = 10 - g;
}
if(y == b[b.length - 1]){
System.out.println("yse");
}else{
System.out.println("no");
}
}

}

你可能感兴趣的:(Java)