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