I am creating a batch program that reads an external input file that contains
credit card numbers and then sums the digits(from right to left), starting at the
last digit and skipping every other digit. I have to treat the input as a String and not
numeric. My code looks like:
int oddSum = 0, digit = 0;
for(int odd = (cardNumber.length() - 1); odd >= 0; odd = odd - 2)
{
digit = Integer.parseInt(cardNumber);
oddSum += digit;
}
But String cardNumber is the whole String, while I just need the single digit. Say:
cardNumber = "4388576018402626";
How can I get, let's say "6", turned into an integer?