Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class OddEvenSum {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- int oddSum = 0, evenSum = 0;
- for (int i = 1; i <= n; i++) {
- int num = Integer.parseInt(scanner.nextLine());
- if (i % 2 == 1) {
- oddSum += num;
- } else {
- evenSum += num;
- }
- }
- if (oddSum == evenSum) {
- System.out.printf("Yes\nSum = %d\n", oddSum);
- } else {
- System.out.printf("No\nDiff = %d\n", Math.abs(oddSum - evenSum));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement