martinvalchev

Left And Right Sum

Nov 4th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  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.         int n = Integer.parseInt(scanner.nextLine());
  7.         int sumLeft = 0;
  8.         int sumRight = 0;
  9.  
  10.         for (int i = 0; i < n ; i++) {
  11.             int curentNumberRight = Integer.parseInt(scanner.nextLine());
  12.             sumRight += curentNumberRight;
  13.         }
  14.  
  15.         for (int i = 0; i < n ; i++) {
  16.             int curentNumberLeft = Integer.parseInt(scanner.nextLine());
  17.             sumLeft += curentNumberLeft;
  18.         }
  19.  
  20.         if ( sumRight == sumLeft) {
  21.             System.out.println("Yes, sum = " + sumLeft);
  22.         } else {
  23.             System.out.println("No, diff = " + Math.abs(sumRight - sumLeft));
  24.         }
  25.  
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment