SHARE
TWEET

Untitled

a guest May 25th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class OddEven {
  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 evenSum = 0;
  10.         int oddSum = 0;
  11.         for (int i = 1; i <= n ; i++){
  12.             int num = Integer.parseInt(scanner.nextLine());
  13.  
  14.             if (i % 2 == 0 ){
  15.                 evenSum = evenSum + num;
  16.             }else{
  17.                 oddSum = oddSum + num;
  18.             }
  19.         }
  20.         if (evenSum == oddSum){
  21.             System.out.printf("Yes%nSum = %d", evenSum);
  22.         }else{
  23.             System.out.printf("No%nDiff = %d", Math.abs( evenSum - oddSum));
  24.         }
  25.     }
  26. }
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