I have a task with checking ID number and I must check if this ID has 11 characters, if those characters are digits and I must check control number. Number is correct when this equation is correct:
ID = abcdefghijk
(1*a+3*b+7*c+9*d+1*e+3*f+7*g+9*h+1*i+3*j+1*k) % 10 = 0
Sample correct ID is: 49040501580
And here is my program. I don't know how to check if ID is digit and why it isn't correct. Anyone help? XD Thank you in advance :3
import java.util.*;
public class wat {
public static void main(String[] args) {
char[] weights = {1, 3, 7, 9, 1, 3, 7, 9, 1, 3, 1};
System.out.print("Enter next digits your ID number: ");
Scanner keyboard = new Scanner(System.in);
String number = keyboard.nextLine();
char[] ofm = number.toCharArray();
Character[] id = new Character[ofm.length];
for (int i = 0; i < ofm.length; i++) {
id[i] = ofm[i];
System.out.print(id[i] + " ");
int length = id.length;
if (length == 11) {
System.out.println("This ID number has 11 digits");
System.out.println("Checking of the control number");
int amount = 0;
amount = id[i] * weights[i];
System.out.println(amount);
int result = 0;
result = amount % 10;
if (result == 0) {
System.out.println("ID number is correct");
} else {
System.out.println("ID number is not correct");
break;
}
} else {
System.out.print("This ID number hasn't 11 digits.");
break;
}
}
}
}