Yes, I'm another college student seeking help. Yes I have a textbook, that I read and self-teach myself. Yes I go to class. Yes my brain is fried working on my own luhn algorithm and credit card validation java program. Not asking for pure answers, just got myself mixed up in int and String values. Any ideas would help me on how to correct this little mess or an idea on where to look. I self taught myself constructors over the weekend but I'm still a bit nervous on trying to implement any, so I'm not using any here. The whole idea behind them is a bit...logically disorienting anyways. Any ideas on the below?
I need to check the incoming value...but if I use keyboard.nextInt I cannot check each digit with charAt later to verify using the luhn algorithm. So I made a string and converted to int to check the length. I think I need to change my while boolean statement to boolean values, does this mean I should use more variables? I'll try doing this in the mean time...
Thanks,
--Steve
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();
int i = s.length(16); // This is the problem I think!!
int sum = 0;
int b = sum;
int n = 9;
while (i != 16) // This also giving me problems
{
System.out.println("Please enter another credit card number: ");
s = keyboard.next();
}