Advertisement
Guest User

Untitled

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