morski77

OddEvenSum

Oct 8th, 2016
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class OddEvenSum {
  4. public static void main(String[] args) {
  5. Scanner input = new Scanner(System.in);
  6. int a =input.nextInt();
  7. int sum = 0;
  8. int num = 0;
  9. for (int i = 0; i < a; i++) {
  10. int b = input.nextInt();
  11.  
  12. if (i % 2 == 0) {
  13. sum += b;
  14. } else {
  15. num += b;
  16. }
  17.  
  18. }if (sum == num) {
  19. System.out.println("Yes");
  20. System.out.println("sum = " + sum);
  21. } else {
  22. int result = Math.abs(sum - num);
  23. System.out.println("No");
  24. System.out.println("diff = " + result);
  25. }
  26.  
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment