Hi im trying to implement the Mod 10 as in the Luhn Algorith on a credit card number so it can validate if its a :/ ...valid account number.
The above link shows what im doing, now all im doing is the validation procces im stuck on "Step 2". I know how to seperate a single double digit number and add them but i dont know where to put it can someone guide me the right direction? and it is not a assignment i just want to learn about methods and array and thought this would be a good thing to start with. Here is what i have so far.HTML Code:http://www.codeproject.com/Tips/515367/Validate-credit-card-number-with-Mod-10-algorithm
public class card { public static void main(String[] args) { //Just experimenting how to seperate a double digit int and add them? String s = "16"; String num1 = s.substring(0,1); String num2 = s.substring(1,2); int n1 = Integer.parseInt(num1); int n2 = Integer.parseInt(num2); int answer = n1+n2; System.out.println(answer); //^^^^^TEST! DONT KNOW WHERE TO PUT IT??? OR HOW TO USE IT // My array(Credit Card number i will figure out at the end on how to get this array as user input) int cardNumb[] = {4,0,1,2,8,8,8,8,8,8,8,8,1,8,8,1}; validate(cardNumb);//Calling my method that multiplies every second value by two for(int y: cardNumb) System.out.print(" "+y); } public static void validate(int x[] ){ for (int i = 0; i < 10; i+=2){ x[i]*=2; } } }