Advertisement
mark79

Java Fundamentals - From Left to The Right

Aug 22nd, 2019
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. import java.math.BigInteger;
  2. import java.util.Scanner;
  3.  
  4. public class FromLeftToTheRight {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         int n = Integer.parseInt(scanner.nextLine());
  9.  
  10.         for (int i = 0; i < n; i++) {
  11.             BigInteger leftNum = scanner.nextBigInteger();
  12.             BigInteger rightNum = scanner.nextBigInteger();
  13.  
  14.             BigInteger num;
  15.             if (leftNum.compareTo(rightNum) > 0) {
  16.                 num = leftNum;
  17.             } else {
  18.                 num = rightNum;
  19.             }
  20.  
  21.             int totalDigitSum = 0;
  22.  
  23.             num = num.abs();
  24.  
  25.             while(num.intValue() != 0){
  26.                 totalDigitSum += num.remainder(BigInteger.valueOf(10)).intValue();
  27.                 num = num.divide(BigInteger.valueOf(10));
  28.             }
  29.  
  30.             System.out.println(totalDigitSum);
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement