Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Luhn Algorithm(Mod10) Help (Beginner)

  1. #1
    Junior Member IBeeJava's Avatar
    Join Date
    Mar 2013
    Location
    Winnipeg
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Luhn Algorithm(Mod10) Help (Beginner)

    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.
    HTML Code:
    http://www.codeproject.com/Tips/515367/Validate-credit-card-number-with-Mod-10-algorithm
    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.

    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;	
     
     
    		}	
     
    	}
    }



  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,273
    Thanks
    56
    Thanked 2,372 Times in 2,343 Posts

    Default Re: Luhn Algorithm(Mod10) Help (Beginner)

    i dont know where to put it
    Can you explain the problem?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member IBeeJava's Avatar
    Join Date
    Mar 2013
    Location
    Winnipeg
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Luhn Algorithm(Mod10) Help (Beginner)

    Well i am confused about the syntax, i don't know where that chunk of code is suppose to go (The part where it separates all single int with double digit values and adds them) so the outcome after i run the code i got 8 0 2 2 16 8 16 8 16 8 8 8 1 8 8 1 how do i make it 8 0 2 2 7 8 7 8 7 8 8 8 1 8 8 1 , so the double digits as in the 16 i separate 1 and 6 then add which is 7 i dont know where to apply that chunk, i am just really confused and sorry i am really bad t explaining things :S

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,273
    Thanks
    56
    Thanked 2,372 Times in 2,343 Posts

    Default Re: Luhn Algorithm(Mod10) Help (Beginner)

    double digits as in the 16 i separate 1 and 6 then add which is 7 i dont know where to apply that chunk
    Is that explained in the algorithm that you are trying to code?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member IBeeJava's Avatar
    Join Date
    Mar 2013
    Location
    Winnipeg
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Luhn Algorithm(Mod10) Help (Beginner)

    Quote Originally Posted by Norm View Post
    Is that explained in the algorithm that you are trying to code?
    Nope, its from a random site and they are using C# i believe to implement the process. I do know its been used with java i'm just a bit confused as to how i split the double valued integers and add them inside the array and sorry for the late reply i haven't been online for a while

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,273
    Thanks
    56
    Thanked 2,372 Times in 2,343 Posts

    Default Re: Luhn Algorithm(Mod10) Help (Beginner)

    split the double valued integers
    Is the variable a double or an int? They are different data types.
    Or are you referring to int values in the range from 10 to 99?

    The % and / operators can be used to get the separate digits from an int variable.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Huffman Algorithm Help
    By Chewybakas in forum Algorithms & Recursion
    Replies: 6
    Last Post: February 20th, 2013, 10:40 AM
  2. Implementing an algorithm
    By me_newbie in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 16th, 2012, 09:50 PM
  3. all i need is algorithm
    By coder.freak in forum Paid Java Projects
    Replies: 3
    Last Post: April 6th, 2011, 12:11 PM
  4. [SOLVED] Algorithm Help
    By aussiemcgr in forum Java Theory & Questions
    Replies: 2
    Last Post: September 10th, 2010, 05:12 PM
  5. algorithm
    By AmmrO in forum Algorithms & Recursion
    Replies: 13
    Last Post: September 24th, 2009, 10:18 PM

Tags for this Thread