static boolean checkStandardUPCEANChecksum(CharSequence s) throws FormatException {
  int length=s.length();
  if (length == 0) {
    return false;
  }
  int sum=0;
  for (int i=length - 2; i >= 0; i-=2) {
    int digit=(int)s.charAt(i) - (int)'0';
    if (digit < 0 || digit > 9) {
      throw FormatException.getFormatInstance();
    }
    sum+=digit;
  }
  sum*=3;
  for (int i=length - 1; i >= 0; i-=2) {
    int digit=(int)s.charAt(i) - (int)'0';
    if (digit < 0 || digit > 9) {
      throw FormatException.getFormatInstance();
    }
    sum+=digit;
  }
  return sum % 10 == 0;
}

static boolean checkStandardUPCEANChecksum ( CharSequence s ) throws FormatException { int length = s . length ( ) ; if ( length == 0 ) { return false ; } int sum = 0 ; for ( int i = length - 2 ; i >= 0 ; i -= 2 ) { int digit = ( int ) s . charAt ( i ) - ( int ) '0' ; if ( digit < 0 || digit > 9 ) { throw FormatException . getFormatInstance ( ) ; } sum += digit ; } sum *= 3 ; for ( int i = length - 1 ; i >= 0 ; i -= 2 ) { int digit = ( int ) s . charAt ( i ) - ( int ) '0' ; if ( digit < 0 || digit > 9 ) { throw FormatException . getFormatInstance ( ) ; } sum += digit ; } return sum % 10 == 0 ; }
computes the upc / ean checksum on a string of digits , and reports whether the checksum is correct or not .
