# Untitled

a guest
Sep 23rd, 2022
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import java.util.Scanner;
2.
3. public class P02FromLeftToTheRight {
4.     public static void main(String[] args) {
5.         /*You will receive a number that represents how many
6.         lines we will get as input. On the next N lines, you will receive
7.         a string with 2 numbers separated by a single space.
8.         You need to compare them. If the left number is greater than the
9.         right number, you need to print the sum of all digits in the left
10.         number, otherwise, print the sum of all digits in the right number.
11.         * */
12.         Scanner scanner = new Scanner(System.in);
13.
14.         int n = Integer.parseInt(scanner.nextLine());
15.         int sum = 0;
16.
17.         for (int i = 0; i < n; i++) {
18.             String[] input = scanner.nextLine().split(" ");
19.             String firstElement = String.valueOf(input[0]);
20.             String secondElement = String.valueOf(input[1]);
21.             long firstNumber = Long.parseLong(input[0]);
22.             long secondNumber = Long.parseLong(input[1]);
23.             sum = 0;
24.
25.             if (firstNumber >= secondNumber) {
26.                 for (int j = 0; j < firstElement.length(); j++) {
27.                     if (firstElement.charAt(j) != '-') {
28.                     int symbol = Integer.parseInt(String.valueOf(firstElement.charAt(j)));
29.                     sum += symbol;
30.                     }
31.                 }
32.             } else {
33.                 for (int j = 0; j < secondElement.length(); j++) {
34.                     if (secondElement.charAt(j) != '-') {
35.                     int symbol = Integer.parseInt(String.valueOf(secondElement.charAt(j)));
36.                     sum += symbol;
37.                     }
38.                 }
39.             }
40.             System.out.println(sum);
41.         }
42.     }
43. }