borkins

07. Left and Right Sum

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