Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    /**
     * Calculate modulo 10 checksom of GTIN
     *
     * @param gtin GTIN
     * @return Checksum
     */
    private static Integer calculateChecksum(String gtin) {
        Integer sum = 0;
        for (int i = 0; i < gtin.length(); i++) {
            Integer temp = Integer.valueOf(gtin.substring(gtin.length() - i - 1, gtin.length() - i));
            if ((i % 2) == 0) {
                sum += (temp * 3);
            } else {
                sum += (temp);
            }
        }
        return (sum % 10);
    }
}