public boolean isValid(String ccNum) { boolean isValid = false; int number [] = {}; char ccNumArray [] = ccNum.toCharArray(); //get number as int array; also strip any non-numeric characters out, //such as spaces. int intArray [] = toIntArray(ccNumArray); //implement method to turn this into an intarray // reverse the cc number preparatory to checksum calculations number = reverse(intArray); //implement method to reverse order int len = number.length; int sum = 0; for(int i = 0; i < len; i++) { int num = number[i]; /* this is the checksum digit; it's *never* doubled. Just add * it to the sum */ if(i == 0) { sum += num; continue; } /* these are the odd-numbered positions in the array; they * should be doubled, and if the result is > 10, the two digits * should be added together and then added to the sum */ if(i % 2 != 0) { num *=2; sum += (num / 10) + (num % 10); } /* these are the even-numbered positions in the array (except * for position 0). These are never doubled, just added to the * sum */ else { sum += num; } } /* if the sum is evenly divisible by 10 (there is no remainder after * the division), then the number is a valid number according to the * luhn algorithm */ if(sum % 10 == 0) { isValid = true; } return isValid; }