Advertisement
SotirovG

LeftAndRightSum_09

Oct 3rd, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class LeftRightSum_09 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         // leftSum & rightSum
  7.         int loopNum = Integer.parseInt(scanner.nextLine());
  8.  
  9.         int leftSum = 0;
  10.         int rightSum = 0;
  11.         int diff = 0;
  12.         for (int i = 1; i <= loopNum; i++) {
  13.             int currentNumb = Integer.parseInt(scanner.nextLine());
  14.             leftSum += currentNumb;
  15.         }
  16.         for( int i = 1; i <= loopNum; i++ ){
  17.             int currentNum = Integer.parseInt(scanner.nextLine());
  18.             rightSum += currentNum;
  19.  
  20.         }
  21.         if (leftSum == rightSum) {
  22.  
  23.             System.out.println("Yes, sum = " + leftSum);
  24.  
  25.         } else {
  26.             diff = Math.abs(leftSum - rightSum);
  27.             System.out.println("No, diff = " + diff);
  28.  
  29.         }
  30.  
  31.  
  32.     }
  33.  
  34. }
  35.  
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement