Every last barcode number would be the result of an account with the other previous numbers. So store the 13 , 12 or 11 digits in an array using strings and then convert them to integers.
After that, make all numbers in odd positions * 1 and numbers in even positions * 1 (ie himself, after that, add all results, store this result in another variable and divide by 10, (if you use double pass for integer).
Add this result to 1 and then multiply by 10, after all subtract the stored result with that last result and "voilà", if the last number matches the account then this barcode is correct if it is not incorrect.
int i = 0;
double code[] = new double[13];
double total = 0;
for(i = 0;i < 12;i++)
{
codigo_barra += cody[i];
code[i] = Integer.parseInt(cody[i]);
if(i%2== 0)
{
code[i] *= 3;
}
total += code[i];
}
double t = total;
total /= 10;
int to = (int)total;
to += 1;
to *=10;
to -= t;
if(to == code[13])
{
valida = "Codigo Correto";
}
else
{
valida = "Codigo Incorreto";
}
System.out.println("Resultado: "+to);
I know this library for Android.
– Bruno Wego