Advertisement
veronikaaa86

Half Sum Elements

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