Skip to main content
added 235 characters in body
Source Link

I have reviewed your code and here are my analysis-

use modulo operator(%) to get the remainder in place of using too much mathematics like

long remainder = num - (quotient * 10); //note: it will just shorten your code 
// but will be overhead as well because internally it will 
//perform three operation(multiplication, subtraction, division).
// C = A % B is equivalent to C = A – B * (A / B).

could be simplifysimplified to

long remainder = num % 10;

You don't need an extra method to count divisor it can be done in athe same method it selfitself.

You can merge the both method while extracting the digit itself can check whether itsit's a divisor or not?

static int findDigits(int n) {
    int count = 0;
    int num = n;
    while (n > 0) {
        int r = n % 10;  // to get the remainder
        if (r != 0 && num % r == 0)  // checking for the divisor
            count++;
        n = n / 10;   // using to remove last digit
    }
    return count;
}

Note: if still need more explanation about the code then click here.

I have reviewed your code and here are my analysis-

use modulo operator(%) to get the remainder in place of using too much mathematics like

long remainder = num - (quotient * 10);

could be simplify to

long remainder = num % 10;

You don't need extra method to count divisor it can be done in a same method it self.

You can merge the both method while extracting the digit itself can check whether its a divisor or not?

static int findDigits(int n) {
    int count = 0;
    int num = n;
    while (n > 0) {
        int r = n % 10;  // to get the remainder
        if (r != 0 && num % r == 0)  // checking for the divisor
            count++;
        n = n / 10;   // using to remove last digit
    }
    return count;
}

Note: if still need more explanation about the code then click here.

I have reviewed your code and here are my analysis-

use modulo operator(%) to get the remainder in place of using too much mathematics like

long remainder = num - (quotient * 10); //note: it will just shorten your code 
// but will be overhead as well because internally it will 
//perform three operation(multiplication, subtraction, division).
// C = A % B is equivalent to C = A – B * (A / B).

could be simplified to

long remainder = num % 10;

You don't need an extra method to count divisor it can be done in the same method itself.

You can merge both method while extracting the digit itself can check whether it's a divisor or not?

static int findDigits(int n) {
    int count = 0;
    int num = n;
    while (n > 0) {
        int r = n % 10;  // to get the remainder
        if (r != 0 && num % r == 0)  // checking for the divisor
            count++;
        n = n / 10;   // using to remove last digit
    }
    return count;
}

Note: if still need more explanation about the code then click here.

Minor formatting
Source Link
Stephen Rauch
  • 4.2k
  • 12
  • 23
  • 36

I have reviewed your code and here are my analysis-

use modulo operator(%) to get the remainder in place of using too much mathematics like

  long remainder = num - (quotient * 10);

could be simplify to   

  

could be simplify to

long remainder = num % 10;

You don't need extra method to count divisor it can be done in a same method it self.

You can merge the both method while extracting the digit itself can check whether its a divisor or not?

static int findDigits(int n) {
        int count = 0;
        int num = n;
        while (n > 0) {
            int r = n % 10;  // to get the remainder
            if (r != 0 && num % r == 0)  // checking for the divisor
                count++;
            n = n / 10;   // using to remove last digit
        }
        return count;
    }

Note: if still need more explanation about the code then click here.

I have reviewed your code and here are my analysis-

use modulo operator(%) to get the remainder in place of using too much mathematics like

  long remainder = num - (quotient * 10);

could be simplify to   

  long remainder = num % 10;

You don't need extra method to count divisor it can be done in a same method it self.

You can merge the both method while extracting the digit itself can check whether its a divisor or not?

static int findDigits(int n) {
        int count = 0;
        int num = n;
        while (n > 0) {
            int r = n % 10;  // to get the remainder
            if (r != 0 && num % r == 0)  // checking for the divisor
                count++;
            n = n / 10;   // using to remove last digit
        }
        return count;
    }

Note: if still need more explanation about the code then click here.

I have reviewed your code and here are my analysis-

use modulo operator(%) to get the remainder in place of using too much mathematics like

long remainder = num - (quotient * 10);

could be simplify to

long remainder = num % 10;

You don't need extra method to count divisor it can be done in a same method it self.

You can merge the both method while extracting the digit itself can check whether its a divisor or not?

static int findDigits(int n) {
    int count = 0;
    int num = n;
    while (n > 0) {
        int r = n % 10;  // to get the remainder
        if (r != 0 && num % r == 0)  // checking for the divisor
            count++;
        n = n / 10;   // using to remove last digit
    }
    return count;
}

Note: if still need more explanation about the code then click here.

Source Link

I have reviewed your code and here are my analysis-

use modulo operator(%) to get the remainder in place of using too much mathematics like

  long remainder = num - (quotient * 10);

could be simplify to   

  long remainder = num % 10;

You don't need extra method to count divisor it can be done in a same method it self.

You can merge the both method while extracting the digit itself can check whether its a divisor or not?

static int findDigits(int n) {
        int count = 0;
        int num = n;
        while (n > 0) {
            int r = n % 10;  // to get the remainder
            if (r != 0 && num % r == 0)  // checking for the divisor
                count++;
            n = n / 10;   // using to remove last digit
        }
        return count;
    }

Note: if still need more explanation about the code then click here.