galinyotsev123

ProgBasics06For-Loop-Y04EqualPairs

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