Skip to content

Instantly share code, notes, and snippets.

@vlfig
Created June 14, 2012 17:57
Show Gist options
  • Save vlfig/2931792 to your computer and use it in GitHub Desktop.
Save vlfig/2931792 to your computer and use it in GitHub Desktop.
Vessel, ship IMO number validator, validation function
public static final boolean isImoValid(String imo) {
if (imo == null || imo.length() != 7) {
return false;
}
char[] a = imo.toCharArray();
int sum = 0;
for(int i = 0; i < 6; i++) {
sum += (a[i]-48)*(a.length-i);
}
return sum % 10 == a[6]-48;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment