Advertisement
Spocoman

02. From Left to The Right

Oct 19th, 2024
55
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. class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int n = Integer.parseInt(scanner.nextLine()),
  7.             index, leftNumber, rigthNumber, sum = 0;
  8.         String input, left, rigth, number;
  9.        
  10.         for (int i = 0; i < n; i++) {
  11.             input = scanner.nextLine();
  12.             index = input.indexOf(" ");
  13.             left = input.substring(0, index);
  14.             rigth = input.substring(index + 1);
  15.             number = Long.parseLong(left) > Long.parseLong(rigth) ? left : rigth;
  16.    
  17.             for (int j = 0; j < number.length(); j++) {
  18.                 if (number.charAt(j) == '-') {
  19.                     continue;
  20.                 }
  21.                 sum += Integer.parseInt(number.substring(j, j + 1));
  22.             }
  23.          
  24.             System.out.println(sum);
  25.             sum = 0;
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement