I am creating a batch program that reads an external input file containing
and then sums the numbers (from right to left), starting with
last digit and skipping every other digit. I should treat the input as a string, not
Numerical. My code looks like this:
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 a whole string, and I need only one digit. Say:
cardNumber = "4388576018402626";
How can I get, say, "6" turned into an integer?
source share