deyanivanov966

09. Left and Right Sum

Oct 9th, 2020 (edited)
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.62 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class LeftAndRightSum {
  3.     public static void main(String[] args) {
  4.         Scanner scan = new Scanner(System.in);
  5.         int n = Integer.parseInt(scan.nextLine());
  6.         int leftSum=0; int rightSum=0;
  7.         for (int left=1; left<=n; left++){
  8.             leftSum += scan.nextInt();
  9.         }for(int right=1; right<=n; right++) {
  10.             rightSum += scan.nextInt();
  11.         }
  12.         if (leftSum == rightSum){
  13.             System.out.printf("Yes, sum = %d",leftSum);
  14.         }else {
  15.             System.out.printf("No, diff = %d",Math.abs(leftSum-rightSum));
  16.         }
  17.     }
  18. }
  19.  
Add Comment
Please, Sign In to add comment