/** * Validate checkdigit of 9 digit number, * e.g. Canadian SIN Number. * input is in ints d1..d9 as ints, not chars. * * @return true if checkdigit is as expected. */ boolean isCheckDigitValid() { int weightedSumOfDigits = d1 + z ( d2 ) + d3 + z ( d4 ) + d5 + z ( d6 ) + d7 +z ( d8 ) + d9; return weightedSumOfDigits % 10 == 0; } private int z ( int digit) { // 0->0 1->2 2->4 3->6 4->8 5->10->1 6->12->3 7->14->5 8->16->7 9->18->9 if ( digit == 9 ) return 9; else return( digit * 2 ) % 9; }