Package edu.cnm.deepdive
Class Luhn
java.lang.Object
edu.cnm.deepdive.Luhn
public abstract class Luhn extends Object
This class defines a single static method,
isValid(String)
method, which implements the
Luhn algorithm to check the validity
of a String
of digits. Implementation of this method is included in the practical exam
problems of the Deep Dive Coding Java training programs.-
Method Summary
-
Method Details
-
isValid
Performs a check-digit validation of the provided digit string, using the Luhn algorithm.digits
must contain only digit characters, whitespace, and punctuation characters, orIllegalArgumentException
is thrown.- Parameters:
digits
-String
of digit characters.- Returns:
true
ifdigits
is valid;false
otherwise.- Throws:
IllegalArgumentException
- Ifdigits
contains any alphabetic characters.
-