SHARE
TWEET

OddEvenSum

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