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