yovkovbpfps

For Loop Exercise Equal Pairs

Apr 15th, 2019
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 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. int couplesCount=Integer.parseInt(scanner.nextLine());
  7.  
  8. int num1=Integer.parseInt(scanner.nextLine());
  9. int num2=Integer.parseInt(scanner.nextLine());
  10. int previousSum=num1+num2;
  11. int maxDiff=0;
  12.  
  13. for (int i=2;i<=couplesCount; i++){
  14. num1=Integer.parseInt(scanner.nextLine());
  15. num2=Integer.parseInt(scanner.nextLine());
  16. int currentSum=num1+num2;
  17. if (currentSum != previousSum ){
  18. maxDiff=Math.abs(currentSum-previousSum);
  19. previousSum=currentSum;
  20. }
  21. }
  22.  
  23. if (maxDiff==0){
  24. System.out.printf("Yes, value=%d",previousSum);
  25. }else{
  26. System.out.printf("No, maxdiff=%d",maxDiff);
  27. }
  28.  
  29. }
  30. }
Add Comment
Please, Sign In to add comment