Advertisement
Ivakis

Еднакви двойки

Aug 26th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. import java.text.DecimalFormat;
  2. import java.util.Scanner;
  3.  
  4. public class demo {
  5. public static void main(String[] args) {
  6. Scanner scanner = new Scanner(System.in);
  7.  
  8. int count = Integer.parseInt(scanner.nextLine());
  9.  
  10. int dif = 0;
  11. int maxDif = 0;
  12.  
  13. int lastSum = 0; //3
  14.  
  15. for (int i = 0; i < count; i++) {
  16. int firstNum = Integer.parseInt(scanner.nextLine());
  17. int secondNum = Integer.parseInt(scanner.nextLine());
  18.  
  19. int sum = firstNum + secondNum;
  20.  
  21. if (i > 0) {
  22. dif = Math.abs(sum - lastSum);
  23. }
  24.  
  25. if( i > 0 && Math.abs(sum - lastSum) > maxDif){
  26. maxDif = Math.abs(sum - lastSum);
  27. }
  28.  
  29. lastSum = sum;
  30.  
  31. }
  32.  
  33. if(dif == 0) {
  34. System.out.printf("Yes, value=%d", lastSum);
  35. }else{
  36. System.out.printf("No, maxdiff=%d", maxDif);
  37. }
  38.  
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement