Advertisement
Kathy2905

LeftAndRightSum

Oct 15th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class LeftAndRightSum {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int n = Integer.parseInt(scanner.nextLine());
  8.  
  9.         int left = 0;
  10.         int right = 0;
  11.  
  12.  
  13.         for (int i = 0; i <  2 * n; i++) {
  14.  
  15.             //i == 0 -> 10;            //i == 2 -> 60;
  16.             //i == 1 -> 90;            //i == 3 -> 40;
  17.  
  18.             int num = Integer.parseInt(scanner.nextLine());
  19.             if (i < n) {
  20.                 left += num;
  21.             }else {
  22.                 right += num;
  23.             }
  24.         }
  25.         int diff = Math.abs(left - right);
  26.  
  27.         if (diff == 0) {
  28.             System.out.printf("Yes, sum = %d", left);
  29.         } else {
  30.             System.out.printf("No, diff = %d", diff);
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement