Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class EANValidator {
- public static boolean validate(final String eanCode) {
- int checksum;
- char[] s = eanCode.toCharArray();
- int s1 = s[0];
- int s2 = s[1];
- int sum;
- for (int i = 0; i < s.length; i++) {
- if (i % 2 == 0) {
- s1 += (s[i] * 3);
- } else {
- s2 += s[i];
- }
- }
- sum = s1 + s2;
- if (sum % 10 == 0) {
- checksum = 0;
- } else {
- checksum = 10 - (sum % 10);
- }
- if (checksum == s[(s.length - 1)]) {
- return true;
- } else {
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement