All pastes #166433 Raw Edit

Something

public java v1 · immutable
·published 2006-09-10 22:19 UTC
rendered paste body
import chn.util.*;public class UPCChecker{    private long checkdigit;    private long[] numArray = new long[11];    public long getDigit(long code)    {        long even = 0;        long odd = 0;        long sum = 0;                for(int i=10; i>=0; i--)        {            numArray[i] = (long)(code%10);            code = code/10;          }                 for(int i = 0; i <(numArray.length-1); i+=2)        {            odd = odd + numArray[i];        }        for(int i = 1; i <(numArray.length-1); i+=2)        {            even = even + numArray[i];        }                  sum = (odd * 3) + even;                checkdigit = sum%10;		if(checkdigit != 0)		  checkdigit = 10 - checkdigit;				return checkdigit;					}		public boolean isValid()	{	    boolean valid;        if (checkdigit == numArray[10])        {            valid = true;        }        else        {            valid = false;        }    return valid;       }	    }