Advertisement
Lyubohd

Left and Right Sum

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