credit card validation java
Google I/O 2009 – App Engine: Now Serving Java
How do you locate a number in a given long number in java?
Say the input value was given as 4561234, and I want to locate the integer in position 3 starting from the left and use that value which is 2 for some calculation. I’m trying to write a credit card validation program, but I’m stuck on figuring out how to locate the value in a position in a given long number.
Can anyone help?
If the number in question is a credit card number, you do not want to use a numerical data type for it at all. You want to use a String. This is because a credit card number isn’t a number; it happens to be a string of numerals, but it is meaningless when considered as a numerical value.
Manipulating Strings and substrings is quite easy in Java. Take a look at the String.substring() and String.charAt() methods.
