SHARE
TWEET

Half Sum Element [Mimi][PB]

damesova May 23rd, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top