todor_boichev

Untitled

Sep 16th, 2020
206
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 = scanner.nextInt();
  8.  
  9.         int leftSum = 0;
  10.         int rightSum = 0;
  11.  
  12.         for (int i = 1; i <= n ; i++) {
  13.             leftSum = leftSum + scanner.nextInt();
  14.         }
  15.         for (int i = 1; i <= n ; i++) {
  16.             rightSum = rightSum + scanner.nextInt();
  17.         }
  18.  
  19.         if (leftSum == rightSum){
  20.             System.out.println(" Yes, sum = " + leftSum);
  21.         }else {
  22.             int difference = Math.abs(leftSum - rightSum);
  23.             System.out.println("No, diff = " + difference);
  24.         }
  25.  
  26.  
  27.     }
  28. }
  29.  
RAW Paste Data