simple java solution || beat 100 % || num%10
Intuition\nWe know that to get the last digit of a number we do (number%10). \nSo, from this knowledge we can easily find sum and product of digits of a number.
# Intuition\nWe know that to get the last digit of a number we do (number%10). \nSo, from this knowledge we can easily find sum and product of digits of a number.\n\n# Complexity\n- Time complexity:\nO(n)\n\n\n# Code\n```\nclass Solution {\n    public int subtractProductAndSum(int n) {\n        int sum = 0;\n        int product = 1;\n        int a = n;\n        while(a>0) {\n            sum += a%10;\n            a /= 10;\n        }\n        a = n;\n        while(a>0) {\n            product *= a%10;\n            a /= 10;\n        }\n        return product-sum;\n    }\n}\n```
['Java']