borkins

10. Half Sum Element

Mar 30th, 2017
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1. /**
  2.  * Project: Loops - created by borkins on 2017-03-29.
  3.  */
  4.  
  5. import java.util.Scanner;
  6.  
  7. public class _10_HalfSumElement
  8. {
  9.     public static void main(String[] args)
  10.     {
  11.         Scanner console = new Scanner(System.in);
  12.        
  13.         int n = Integer.parseInt(console.nextLine());
  14.        
  15.         int max = Integer.MIN_VALUE;
  16.         int sum = 0;
  17.        
  18.         for (int i = 0; i < n; i++)
  19.         {
  20.             int num = Integer.parseInt(console.nextLine());
  21.            
  22.             if (num > max) max = num;
  23.             sum += num;
  24.         }
  25.        
  26.         sum -= max;
  27.         int diff = Math.abs(sum - max);
  28.        
  29.         System.out.println((diff == 0) ? "Yes Sum = " + max : "No Diff = " + diff);
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment