Advertisement
paykova

HalfSumElements

Oct 11th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ElementEqual {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int n = Integer.parseInt(scanner.nextLine());
  8. double sum = 0;
  9. double result = 0;
  10. double bigN = Integer.MIN_VALUE;
  11.  
  12. for (int i = 0; i < n; i++) {
  13. int num = Integer.parseInt(scanner.nextLine());
  14. sum += num;
  15. if (num > bigN) {
  16. bigN = num;
  17. }
  18. } if (bigN == sum - bigN) {
  19. System.out.printf("Yes Sum = %.0f", bigN);
  20. } else {
  21. result = (bigN - (sum - bigN));
  22. System.out.printf("No diff = %.0f", Math.abs(result));
  23. }
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement