Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public int subtractProductAndSum(int n) {
- String nString = String.valueOf(n);
- int product = 1, sum = 0, d;
- for (int i = 0;i < nString.length();i++) {
- d = Character.getNumericValue(nString.charAt(i));
- product *= d;
- sum += d;
- }
- return product - sum;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement