Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Half Sum Element {
- 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++)
- for (int i = 0; i < n; i++) {
- int number = Integer.parseInt(scanner.nextLine());
- if (max < number) {
- max = number;
- }//max element
- sum = sum + number;
- }
- if (sum - max == max) {
- System.out.println("Yes");
- System.out.println("Sum = " + max);
- } else {
- System.out.println("No");
- System.out.println("Diff = " + Math.abs(max - (sum - max)));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement