I am really new to this. I am trying to use the Luhn Algorithm to validate a "person number" (a Swedish social security number). I think the code is almost finished but I don't know what to put in the class "birthDate.length()" and "pos" to make it work. birthDate.length needs to make sure that the string is 10 digits long and "pos" is needed for validation control.
package kund;
import java.util.Scanner;
public class Kund {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("Welcome customer. Please login by using your "
+ "birthdate (yymmddxxxx)");
Scanner input = new Scanner (System.in);
String birthDate = input.next();
int length = birthDate.length();
int sum = 0;
for (int i = 1; pos=length-1; i<=10; i++, pos--){
char tmp = birthDate.charAt(pos);
int num = Integer.parseInt(String.valueOf(tmp));
int produkt;
if (i % 2 != 0){
produkt = num * 1;
}else {
produkt = num * 2;
}
if ( produkt > 9 )
produkt -= 9;
sum += produkt;
boolean korrekt = (sum % 10) == 0;
if (!korrekt){
System.out.println("Invalid.");
}else if(korrekt){
System.out.println("Correct");
}
}
}
}