skipter

Equal Pairs - Java Basics (87% points)

Apr 9th, 2017
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner input = new Scanner(System.in);
  7.  
  8.         int numbers = Integer.parseInt(input.nextLine());
  9.         int biggestSum = Integer.MIN_VALUE;
  10.         int currentSum = 0;
  11.         int smallestSum = Integer.MAX_VALUE;
  12.  
  13.         for (int i = 0; i < numbers ; i++) {
  14.             int firstNumber = Integer.parseInt(input.nextLine());
  15.             int secondNumber = Integer.parseInt(input.nextLine());
  16.             currentSum = firstNumber + secondNumber;
  17.  
  18.             if (biggestSum < currentSum) {
  19.                 biggestSum = currentSum;
  20.             }
  21.             if (smallestSum > currentSum) {
  22.                 smallestSum = currentSum;
  23.             }
  24.  
  25.         }
  26.         if (biggestSum - smallestSum == 0) {
  27.             System.out.printf("Yes, value=" + currentSum);
  28.         } else {
  29.             System.out.printf("No, maxdiff=%s", biggestSum - smallestSum);
  30.         }
  31.     }
  32. }
Add Comment
Please, Sign In to add comment