Advertisement
meteor4o

Java-Fund-DataMore- 02.FromLeftToTheRight

May 29th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P02_FromLeftToTheRight {
  6. public static void main(String[] args) {
  7.  
  8. Scanner sc = new Scanner(System.in);
  9.  
  10. int lines = Integer.parseInt(sc.nextLine());
  11.  
  12. for (int i = 1; i <= lines; i++) {
  13.  
  14. long num1 = Long.parseLong(sc.next());
  15. long num2 = Long.parseLong(sc.next());
  16. int sum = 0;
  17.  
  18. if (num1 > num2) {
  19. double numFirst = Math.abs(num1);
  20. while (numFirst > 0) {
  21.  
  22. sum += (numFirst % 10);
  23. numFirst /= 10;
  24. }
  25. } else {
  26. double numSec = Math.abs(num2);
  27. while (numSec > 0) {
  28. sum += (numSec % 10);
  29. numSec /= 10;
  30. }
  31. }
  32. System.out.println(Math.abs(sum));
  33. }
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement