Hi all,
I'll get to the point. I've been steadily working on my java project which involves the luhn algorithm and the checking of credit card validity. Apparently every college student has taken to the web regarding this one either recently or in past years...I see lots of threads regarding this stuff.
Either way, I have a text book, I go to class, I am learning this stuff. I'm having trouble with only one part of the whole dang thing. I've got myself mixed up between strings and int values. I could really use some help (rather a new set of eyes to look and go "yeah move x over here and your good")
I won't post all of my code as I spent enough time on it...rather keep it as my own. The below is just the first bit, where I challenge for a 16 digit credit card number. I'm doing something wrong but my brain is fried. Any ideas? I self taught myself constructors this weekend...so I'm not using any as of yet, but would think this is a case that might make things quite a bit easier :)
import java.util.Scanner;
import java.util.*;
import java.lang.Math;
public class Luhn22
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
System.out.print ("Please enter your credit card number: ");
System.out.println();
String s = keyboard.next(); // I tried nextInt but I cannot use the charAt function later with integer value
int i = s.length(String, 16); // This is where I go wrong...I can't mask it differently and I attempt to change to integer value
int sum = 0; // Part of my later algorithm
int b = sum; // Part of my later algorithm
int n = 9; // Part of my later algorithm
while (i != 16) // This isn't working either...I need a full proof method to check 16 digits, but it's a start for me and very basic
{
System.out.println("Please enter another credit card number: ");
s = keyboard.next();
}
I understand your not a java forum or a bunch of experts...but if you have a few minutes at work to take a glance, would be appreciated.
Thanks,
--Steve