/**
 * A class that contains examples of digit counting.
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class DigitCounting {
    /**
     * A method to hold the fragments.
     *
     * @param args  The command line arguments
     */
    public static void main(String[] args) {
        int cardNumber, issuer, n;
        
//[cardNumber
        cardNumber = 412831758;
//]cardNumber
//[n
        n = digits(cardNumber);
//]n
    
//[issuer    
        issuer = cardNumber / (int) Math.pow(10.0, n - 3);
//]issuer
        System.out.println(n + "\t" + (int) Math.pow(10.0, n) + "\t" + issuer);


        int figures, income;
//[income
        income = 156720;
//]income

//[figures
        figures = digits(income);
//]figures        
        System.out.println(income + " has " + figures + " figures");
    }

//[pattern
    /**
     * Determine the number of digits in an integer.
     *
     * @param x  The integer of interest
     * @return   The number of digits
     */
    public static int digits(int x) {
        return (int) Math.log10(x) + 1;
    }
//]pattern
}

