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.digitsmust contain only digit characters, whitespace, and punctuation characters, orIllegalArgumentExceptionis thrown.- Parameters:
digits-Stringof digit characters.- Returns:
trueifdigitsis valid;falseotherwise.- Throws:
IllegalArgumentException- Ifdigitscontains any alphabetic characters.
-