All pastes #902863 Raw Edit

Miscellany

public text v1 · immutable
·published 2008-02-13 20:29 UTC
rendered paste body
    public static boolean validate(String ccNumber) {
        boolean odd = false;
	char[] digits = ccNumber.toCharArray();
	int sum = 0;
	for (int i = digits.length - 1; i > -1; i--, odd = !odd) {
            int d = digits[i] - 48;
            if (odd) {
                final int t = d * 2;
                d = (t > 9) ? (t - 9) : (t);
            }
            sum += d;
	}
        return (sum % 10) == 0;
    }