samedi 28 mai 2016

In Java, trying to print how many digits in an integer evenly divide into the whole integer

I'm trying to print how many digits in an integer evenly divide into the whole integer.

Using mod 10 and division by 10, I got the last digits of the integer, and then did mod integer by each last digit. For some reason it's not working and I'm getting errors (https://repl.it/CWWV/3).

Any help would be greatly appreciated!

Scanner in = new Scanner(System.in);
    int singleD, n1;
    int counter = 0;
    int n = in.nextInt();
        n1 = n;
        singleD = n1%10;
        while (n1 > 0 && singleD > 0){
            n1 /= 10;  
            if(n%singleD == 0){
                counter++;
            }
        }
        System.out.println(counter);
        counter = 0;

Aucun commentaire:

Enregistrer un commentaire