daily pastebin goal
25%
SHARE
TWEET

LeftAndRightSum

Kathy2905 Oct 15th, 2018 67 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
  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 = Integer.parseInt(scanner.nextLine());
  8.  
  9.         int left = 0;
  10.         int right = 0;
  11.  
  12.  
  13.         for (int i = 0; i <  2 * n; i++) {
  14.  
  15.             //i == 0 -> 10;            //i == 2 -> 60;
  16.             //i == 1 -> 90;            //i == 3 -> 40;
  17.  
  18.             int num = Integer.parseInt(scanner.nextLine());
  19.             if (i < n) {
  20.                 left += num;
  21.             }else {
  22.                 right += num;
  23.             }
  24.         }
  25.         int diff = Math.abs(left - right);
  26.  
  27.         if (diff == 0) {
  28.             System.out.printf("Yes, sum = %d", left);
  29.         } else {
  30.             System.out.printf("No, diff = %d", diff);
  31.         }
  32.     }
  33. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top