summaryrefslogtreecommitdiff
path: root/sampleUses/src/main/java/LuhnVerification.java
blob: f9ad24146226c2bb0562aadee358524f2fa0fd51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
public class LuhnVerification {

	static boolean checkNumber(String value) {
		int result = 0;
		boolean special = false;
		for (int i = value.length() - 1; i >= 0; i--) {
			int v = value.charAt(i) - '0';
			if (v < 0 || v > 9)
				return false;
			if (special) {
				v = v * 2;
				if (v > 9)
					v = v - 10 + 1;
			}
			result += v;
			special = !special;
		}
		System.out.println(result);
		return result % 10 == 0;
	}

	public static void main(String args[]) {
		System.out.println(checkNumber(""));
	}

}