Advertisement
Krassi_Daskalova

EqualPairs

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