Advertisement
dimipan80

C#Exams 2. Half Sum (on Java Code)

Aug 21st, 2014
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.60 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class _2_HalfSum {
  4.  
  5.     public static void main(String[] args) {
  6.         // TODO Auto-generated method stub
  7.         Scanner scan = new Scanner(System.in);
  8.         int count = scan.nextInt();
  9.  
  10.         long firstSum = 0;
  11.         for (int i = 0; i < count; i++) {
  12.             firstSum += scan.nextInt();
  13.         }
  14.  
  15.         long secondSum = 0;
  16.         for (int i = 0; i < count; i++) {
  17.             secondSum += scan.nextInt();
  18.         }
  19.  
  20.         long difference = Math.abs(firstSum - secondSum);
  21.  
  22.         if (difference == 0) {
  23.             System.out.println("Yes, sum=" + firstSum);
  24.         } else {
  25.             System.out.println("No, diff=" + difference);
  26.         }
  27.     }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement