Advertisement
CR7CR7

leftr

Oct 12th, 2022
584
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class _02_FromLeftToTheRight {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int n = Integer.parseInt(scanner.nextLine());
  8.  
  9.         for (int i = 1; i <= n; i++) {
  10.             double num1 = Double.parseDouble(scanner.next());
  11.             double num2 = Double.parseDouble(scanner.next());
  12.  
  13.             int sum = 0;
  14.             if (num1 > num2) {
  15.                 double numFirst = Math.abs(num1);
  16.                 while (numFirst > 0) {
  17.                     sum += (numFirst % 10);
  18.                     numFirst /= 10;
  19.                 }
  20.             } else {
  21.                 double numSecond = Math.abs(num2);
  22.                 while (numSecond > 0) {
  23.                     sum += (numSecond % 10);
  24.                     numSecond /= 10;
  25.                 }
  26.             }
  27.             System.out.println(Math.abs(sum));
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement