package leetcode;

/**
 * https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer/
 */
public class Problem1281 {
    public int subtractProductAndSum(int n) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1281 prob = new Problem1281();
        System.out.println(prob.subtractProductAndSum(234)); // 15
        System.out.println(prob.subtractProductAndSum(4421)); // 21
    }
}

package leetcode;

/**
 * https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer/
 */
public class Problem1281 {
    public int subtractProductAndSum(int n) {
        int product = 1;
        int sum = 0;
        for (char c : Integer.toString(n).toCharArray()) {
            product *= c - '0';
            sum += c - '0';
        }
        return product - sum;
    }
}

Solve problem 1281