Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package S4_FoorLoops;
- 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 = 1; i <= n; i++) {
- int digit = Integer.parseInt(scanner.nextLine());
- if (digit > maxNum) {
- maxNum = digit;
- }
- //sum = sum + digit;
- sum += digit;
- }
- //sum = sum - maxNum;
- sum -= maxNum;
- if(sum == maxNum) {
- System.out.printf("Yes%nSum = %d", sum);
- } else {
- System.out.printf("No%nDiff = %d", Math.abs(sum - maxNum));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement