Advertisement
YavorGrancharov

LeftAndRightSum

Jan 27th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class LeftAndRightSum {
  4.     public static void main(String[] args) {
  5.         Scanner console = new Scanner(System.in);
  6.         int n = Integer.parseInt(console.nextLine());
  7.         int leftSum = 0;
  8.         int rightSum = 0;
  9.  
  10.         for (int i = 0; i < n; i++) {
  11.             int num = Integer.parseInt(console.nextLine());
  12.             leftSum += num;
  13.         }
  14.         for (int i = 0; i < n; i++) {
  15.             int num = Integer.parseInt(console.nextLine());
  16.             rightSum += num;
  17.         }
  18.         if (leftSum == rightSum) {
  19.             System.out.println("Yes, sum = " + leftSum);
  20.         } else {
  21.             System.out.println("No, diff = " + Math.abs(leftSum - rightSum));
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement