Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class HalfSumElement {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- int max = Integer.MIN_VALUE;
- int sum = 0;
- for (int i = 1; i <= n ; i++) {
- int num = Integer.parseInt(scanner.nextLine());
- sum += num;
- if (num > max) {
- max = num;
- }
- }
- int newSum = Math.abs(sum-max);
- if (max == newSum) {
- System.out.printf("Yes%nSum = %d", max);
- } else {
- System.out.printf("No%nDiff = %d", Math.abs(max-newSum));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement