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 Details

    • isValid

      public static boolean isValid​(String digits) throws IllegalArgumentException
      Performs a check-digit validation of the provided digit string, using the Luhn algorithm. digits must contain only digit characters, whitespace, and punctuation characters, or IllegalArgumentException is thrown.
      Parameters:
      digits - String of digit characters.
      Returns:
      true if digits is valid; false otherwise.
      Throws:
      IllegalArgumentException - If digits contains any alphabetic characters.