grach

Left and Right Sum

Apr 5th, 2020
218
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 scan = new Scanner(System.in);
  6.  
  7.         int n = Integer.parseInt(scan.nextLine());
  8.  
  9.  
  10.         int leftSum = 0;
  11.         int rightSum = 0;
  12.  
  13.         for (int i = 0; i < n; i++) {
  14.             int leftNum = Integer.parseInt(scan.nextLine());
  15.             leftSum = leftSum + leftNum;
  16.         }
  17.         // System.out.println(leftSum);
  18.  
  19.         for (int i = 0; i < n; i++) {
  20.             int rightNum = Integer.parseInt(scan.nextLine());
  21.             rightSum = rightSum + rightNum;
  22.         }
  23.  
  24.  
  25.         if (leftSum == rightSum) {
  26.             System.out.printf("Yes, sum = %d", leftSum);
  27.         } else {
  28.             System.out.printf("No, diff = %d", Math.abs(leftSum - rightSum));
  29.         }
  30.  
  31.  
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment