veronikaaa86

Equal Pairs

Feb 7th, 2018
522
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class EqualPairs {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int n = Integer.parseInt(scanner.nextLine());
  8.  
  9.         int previousSum = 0;
  10.         int currentSum = 0;
  11.         int maxDiff = 0;
  12.         for (int i = 0; i < n; i++) {
  13.             int firstNum = Integer.parseInt(scanner.nextLine());
  14.             int secondNum = Integer.parseInt(scanner.nextLine());
  15.             if (i != 0) {
  16.                 currentSum = firstNum + secondNum;
  17.                 if (Math.abs(currentSum - previousSum) > maxDiff) {
  18.                     maxDiff = Math.abs(currentSum - previousSum);
  19.                 }
  20.             }
  21.             previousSum = firstNum + secondNum;
  22.         }
  23.  
  24.         if (maxDiff == 0) {
  25.             System.out.printf("Yes, value=%d", previousSum);
  26.         } else {
  27.             System.out.printf("No, maxdiff=%d", maxDiff);
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment