Easiest Solution | Java | Beats 100% Leetcoders :)
Get last digit and add it in sum in each iteration ,\nand multiply it in prod in each iteration. And then print their difference.\n\n# Code\njava []\nclass Solu
Get last digit and add it in sum in each iteration ,\nand multiply it in prod in each iteration. And then print their difference.\n\n# Code\n```java []\nclass Solution {\n    public int subtractProductAndSum(int n) {\n        int lastDigit=0;\n        int sum=0;\n        int prod=1;\n        for(int i=n;i>0;i/=10){\n            lastDigit=i%10;\n            sum+=lastDigit;\n            prod*=lastDigit;\n        }\n        int ans=prod-sum;\n        return ans;\n    }\n}\n```
['Java']