SHARE
TWEET

OddEven

a guest Nov 14th, 2019 157 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class OddEvenSum {
  4.     public static void main(String[] args) {
  5.         Scanner scn = new Scanner(System.in);
  6.         int count = Integer.parseInt(scn.nextLine());
  7.         int sumEven = 0;
  8.         int sumOdd = 0;
  9.  
  10.         for (int i = 1; i <= count; i++) {
  11.             int number = Integer.parseInt(scn.nextLine());
  12.  
  13.             if (i % 2 == 0) {
  14.                 sumEven += number;
  15.             } else {
  16.                 sumOdd += number;
  17.             }
  18.         }
  19.  
  20.         if (sumEven == sumOdd) {
  21.             System.out.println("Yes");
  22.             System.out.println("Sum = " + sumEven);
  23.         } else {
  24.             System.out.println("No");
  25.             System.out.println("Diff = " + Math.abs(sumEven - sumOdd));
  26.         }
  27.     }
  28. }
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