galinyotsev123

ProgBasics06For-Loop-Y02halfSumElement

Jan 5th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Y02halfSumElement {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. int count = Integer.parseInt(scanner.nextLine());
  7.  
  8. int maxNum = Integer.MIN_VALUE;
  9. int sum = 0;
  10.  
  11. for (int i = 0; i < count; i++){
  12. int num = Integer.parseInt(scanner.nextLine());
  13. sum += num;
  14.  
  15. if (num > maxNum){
  16. maxNum =num;
  17. }
  18. }
  19. if(sum - maxNum == maxNum){
  20. System.out.printf("Yes%nSum = %d%n", maxNum);
  21. } else {
  22. System.out.printf("No%nDiff = %d%n",
  23. Math.abs(maxNum - (sum - maxNum)));
  24. }
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment