Easy java solution || Beats 100% || 0ms
Using 2 loops and functions\n# Code\n\nclass Solution {\n    int product(int n)\n    {\n        int prod=1;\n        while(n>0)\n        {\n            prod=pro
# Using 2 loops and functions\n# Code\n```\nclass Solution {\n    int product(int n)\n    {\n        int prod=1;\n        while(n>0)\n        {\n            prod=prod*(n%10);\n            n=n/10;\n        }\n        return prod;\n    }\n    int sum(int n)\n    {\n        int add=0;\n        while(n>0)\n        {\n            add=add+(n%10);\n            n=n/10;\n        }\n        return add;\n    }\n    public int subtractProductAndSum(int n) {\n        return product(n)-sum(n);\n    }\n}\n```\n# Using only 1 loop\n```\nclass Solution {\n    public int subtractProductAndSum(int n) {\n        int product=1;\n        int sum=0;\n        while(n>0)\n        {\n            product=product*(n%10);\n            sum=sum+(n%10);\n            n=n/10;\n        }\n        return product-sum;\n    }\n}\n```
['Java']