Advertisement
SophiYo

FromLeftToRight

Feb 1st, 2019
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1. package O2DataTypesAndVar.MoreExercise;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Ex02FromLeftToTheRight {
  6.     public static void main(String[] args) {
  7.         @SuppressWarnings("")
  8.         Scanner scanner = new Scanner(System.in);
  9.  
  10.         int inputNumber = Integer.parseInt(scanner.nextLine());
  11.  
  12.         int counter = 0, sum = 0;
  13.  
  14.         while (counter < inputNumber) {
  15.             String numbersToCompare = scanner.nextLine();
  16.  
  17.             String[] s = numbersToCompare.split(" ");
  18.  
  19.             long numb1 =Long.parseLong(s[0]);
  20.             long numb2 =Long.parseLong(s[1]);
  21.  
  22.             if (numb1 > numb2) {
  23.                 while (numb1 != 0 ) {
  24.                     sum += numb1%10;
  25.                     numb1 /= 10;
  26.                 }
  27.  
  28.                 System.out.println(Math.abs(sum));
  29.  
  30.             } else {
  31.                 while (numb2 != 0 ) {
  32.                     sum += numb2%10;
  33.                     numb2 /= 10;
  34.                 }
  35.                 System.out.println(Math.abs(sum));
  36.             }
  37.  
  38.             sum = 0;
  39.             counter++;
  40.         }
  41.  
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement