Java. One of the rules for my creditcard number is that the sum of the first four digits must be 1 less than the sum of the last four digits, but I think because my number has dashes(-) separating them, it's causing error 5. I need to have the dashes. What should I change in this structure?
int firstfourdigits = 0;
int lastfourdigits = 0;
for(int i=0; i<4; i++)
firstfourdigits = firstfourdigits + Character.getNumericValue(ccNumber.charAt(i));
for (int i=0, m = ccNumber.length()-1; i<4; i++, m--)
lastfourdigits = lastfourdigits + Character.getNumericValue(ccNumber.charAt(m));
if(lastfourdigits!= firstfourdigits -1){
valid = false;
errorCode = 5;
return;
}