Advertisement
Dilyana86

Untitled

May 27th, 2017
532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.67 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class f10HalfSumElement {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.         int n = Integer.parseInt(scan.nextLine());
  7.         int max = Integer.MIN_VALUE;
  8.         int allSum = 0;
  9.         for(int i=0 ; i<n ; i++){
  10.             int num = Integer.parseInt(scan.nextLine());
  11.             allSum = allSum + num;
  12.             if(num > max){
  13.                 max = num;
  14.             }
  15.         }
  16.         if(max == allSum - max){
  17.             System.out.println("Yes Sum = " + max);
  18.         }else{
  19.             System.out.println("No Diff = " + Math.abs(max -(allSum - max)));
  20.         }
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement