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