Given an integer number n, return the difference between the product of its digits and the sum of its digits. code example
Example: Given an integer number n, return the difference between the product of its digits and the sum of its digits.
class Solution {
public int subtractProductAndSum(int n) {
int res=0;
int p=1;
int sum=0;
while(n!=0){
int r=n%10;
n=n/10;
p=p*r;
sum+=r;
}
res=p-sum;
return res;
}
}