Advertisement
stoyanoff

OddEvenSum

Jun 30th, 2020
1,165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement