In case I have to calculate with 16 digits of number maybe 4388576018402626
I want to calculate in three way
way 1. (part14 * 2 + part12 * 2 + part10 * 2 + part8 * 2 + part6 * 2 + part4 * 2 + part2 * 2 +part0 * 2 ) =37
however it outcome error
way 2. (part15 + part13 + part11 + part9 + part7 + part5 + part3 +part1) = 38 however it outcome 66080783
way 3. (way1 + way2) %10 because way 1 error it cannot have any outcome
public static void main(String[] args) {
// TODO Auto-generated method stub
//code for loop of follow program
boolean run = true;
while(run){
//User enter the data
Scanner sc = new Scanner (System.in);
System.out.print("Enter the credit card number:");
String cs = sc.nextLine();
//String divide the 16 number in to one different part
String[] parts = cs.split("");
String part0 = parts[0];
String part1 = parts[1];
String part2 = parts[2];
String part3 = parts[3];
String part4 = parts[4];
String part5 = parts[5];
String part6 = parts[6];
String part7 = parts[7];
String part8 = parts[8];
String part9 = parts[9];
String part10 = parts[10];
String part11 = parts[11];
String part12 = parts[12];
String part13 = parts[13];
String part14 = parts[14];
String part15 = parts[15];
String sd = (part14 * 2 + part12 * 2 + part10 * 2 + part8 * 2 + part6 * 2 + part4 * 2 + part2 * 2 +part0 * 2 );
String sd1 = (part15 + part13 + part11 + part9 + part7 + part5 + part3 +part1);
String sd2 = (sd+sd1);
int sd3 = (sd2%10);
if (sd3 =0)
System.out.println ("The card is valid");
else
System.out.println ("The card is invalid");
}
}
}