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 maxNum = Integer.MIN_VALUE;
- int sum = 0;
- int result=0;
- for (int i = 0; i < n; i++) {
- int num = Integer.parseInt(scanner.nextLine());
- if (num > maxNum) {
- maxNum = num;
- }
- sum += num;
- }
- result=sum-maxNum;
- if (result == maxNum) {
- System.out.println("Yes");
- System.out.printf("Sum= %d%n", maxNum);
- } else {
- System.out.println("No");
- System.out.printf("Diff= %d%n", Math.abs(maxNum-result));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement