Advertisement
VelizarAng

Javabook softuni 5.1

Mar 29th, 2020 (edited)
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner scan = new Scanner(System.in);
  9.         int n = Integer.parseInt(scan.nextLine());
  10.         int sum = 0;
  11.         int diff = 0;
  12.         int sum2 = 0;
  13.  
  14.         for (int i = 1; i <= n; i++) {
  15.              int cn = scan.nextInt();
  16.              int cn2 = scan.nextInt();
  17.              sum = cn + cn2;
  18.              if(sum > sum2){
  19.                  diff = sum - sum2;
  20.              }else{
  21.                  diff = sum2 - sum;
  22.              }
  23.              sum2 = sum;
  24.         }
  25.  
  26.            if (diff == 0) {
  27.                System.out.println("Yes, value=" + sum);
  28.            }else{
  29.                System.out.println("No, maxdiff=" + diff);
  30.            }
  31.  
  32.  
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement