Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class _2_Odd_EvenSum {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner scan = new Scanner(System.in);
- int count = scan.nextInt();
- boolean numIsOdd = true;
- long oddSum = 0;
- long evenSum = 0;
- for (int i = 0; i < 2 * count; i++) {
- if (numIsOdd) {
- oddSum += scan.nextInt();
- } else {
- evenSum += scan.nextInt();
- }
- numIsOdd = !numIsOdd;
- }
- long difference = Math.abs(oddSum - evenSum);
- if (difference == 0) {
- System.out.println("Yes, sum=" + oddSum);
- } else {
- System.out.println("No, diff=" + difference);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement