import java.util.Scanner;
public
class Demo10 {
public static int calc(String s){
int odd =
0;
int even =
0;
int t =
0;
char[] c = s.toCharArray();
if(c.length%
2==
0){
for(
int i=
0;i<c.length;i++){
t = c[i]-
'0';
if(i%
2!=
0){
odd += t;
}
else{
if(t*
2>=
10){
even += t*
2-
9;
}
else{
even += t*
2;
}
}
}
}
else{
for(
int i=
0;i<c.length;i++){
t = c[i]-
'0';
if(i%
2==
0){
odd += t;
}
else{
if(t*
2>=
10){
even += t*
2-
9;
}
else{
even += t*
2;
}
}
}
}
return odd+even;
}
public static void main(String[] args){
Scanner scan =
new Scanner(System.in);
System.out.print(
"输入卡号:");
String s = scan.nextLine();
if(calc(s)%
10==
0){
System.out.println(
"成功");
}
else{
System.out.println(
"失败");
}
}
}
运行结果:
输入卡号
:5432123456788881
成功