Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. public class VMwareOA {
  2. public static int distance(int a, int b) {
  3. int res = 0;
  4. while (a > 0 && b > 0) {
  5. res += Math.abs(a % 10 - b % 10);
  6. a /= 10;
  7. b /= 10;
  8. }
  9. return res;
  10. }
  11.  
  12. public static void main(String[] args) {
  13. // Testcase1: 3
  14. System.out.println(distance(133,343));
  15. // Testcase2: 4
  16. System.out.println(distance(1234,1221));
  17.  
  18. }
  19.  
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement