Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class _2_Pairs {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner scan = new Scanner(System.in);
- String inputLine = scan.nextLine();
- String[] numStr = inputLine.split("[ ]+");
- int previousSum = Integer.parseInt(numStr[0])
- + Integer.parseInt(numStr[1]);
- int maxDiff = 0;
- for (int i = 2; i + 1 < numStr.length; i += 2) {
- int nextSum = Integer.parseInt(numStr[i])
- + Integer.parseInt(numStr[i + 1]);
- int currentDiff = Math.abs(nextSum - previousSum);
- maxDiff = Math.max(maxDiff, currentDiff);
- previousSum = nextSum;
- }
- if (maxDiff == 0) {
- System.out.println("Yes, value=" + previousSum);
- } else {
- System.out.println("No, maxdiff=" + maxDiff);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement