Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class P02FromLeftToTheRight {
- public static void main(String[] args) {
- /*You will receive a number that represents how many
- lines we will get as input. On the next N lines, you will receive
- a string with 2 numbers separated by a single space.
- You need to compare them. If the left number is greater than the
- right number, you need to print the sum of all digits in the left
- number, otherwise, print the sum of all digits in the right number.
- * */
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- int sum = 0;
- for (int i = 0; i < n; i++) {
- String[] input = scanner.nextLine().split(" ");
- String firstElement = String.valueOf(input[0]);
- String secondElement = String.valueOf(input[1]);
- long firstNumber = Long.parseLong(input[0]);
- long secondNumber = Long.parseLong(input[1]);
- sum = 0;
- if (firstNumber >= secondNumber) {
- for (int j = 0; j < firstElement.length(); j++) {
- if (firstElement.charAt(j) != '-') {
- int symbol = Integer.parseInt(String.valueOf(firstElement.charAt(j)));
- sum += symbol;
- }
- }
- } else {
- for (int j = 0; j < secondElement.length(); j++) {
- if (secondElement.charAt(j) != '-') {
- int symbol = Integer.parseInt(String.valueOf(secondElement.charAt(j)));
- sum += symbol;
- }
- }
- }
- System.out.println(sum);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement