Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.37 KB | None | 0 0
  1. class Solution {
  2.     public int subtractProductAndSum(int n) {
  3.         String nString = String.valueOf(n);
  4.         int product = 1, sum = 0, d;
  5.  
  6.         for (int i = 0;i < nString.length();i++) {
  7.             d = Character.getNumericValue(nString.charAt(i));
  8.             product *= d;
  9.             sum += d;
  10.         }
  11.        
  12.         return product - sum;
  13.     }
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement