Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class MyClass {
- public static void main(String args[]) {
- Scanner sc = new Scanner(System.in);
- int n = sc.nextInt();
- int sumEven = 0;
- int sumOdd = 0;
- for (int i = 1; i <= n; i++) {
- int x = sc.nextInt();
- if (i % 2 == 0) {
- sumEven += x;
- } else {
- sumOdd += x;
- }
- }
- if (sumEven == sumOdd) {
- System.out.println("Yes");
- System.out.println("Sum = " + sumEven);
- } else {
- System.out.println("No");
- System.out.println("Diff =" + Math.abs(sumEven - sumOdd));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement