Advertisement
damesova

Half Sum Element [Mimi][PB]

May 23rd, 2019
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 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.         int n = Integer.parseInt(scanner.nextLine());
  7.         int max = Integer.MIN_VALUE;
  8.         int sum = 0;
  9.  
  10.         for (int i = 1; i <= n ; i++) {
  11.             int num = Integer.parseInt(scanner.nextLine());
  12.             sum += num;
  13.  
  14.             if (num > max) {
  15.                 max = num;
  16.             }
  17.         }
  18.  
  19.         int newSum = Math.abs(sum-max);
  20.  
  21.         if (max == newSum) {
  22.             System.out.printf("Yes%nSum = %d", max);
  23.         } else {
  24.             System.out.printf("No%nDiff = %d", Math.abs(max-newSum));
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement