Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class LeftAndRightSum {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. int n = Integer.parseInt(scanner.nextLine());
  7. int leftSum = 0;
  8. int rightSum = 0;
  9. for (int i = 0; i < n; i++) {
  10. int num = Integer.parseInt(scanner.nextLine());
  11. leftSum += num;
  12. }
  13. for (int i = 0; i < n; i++) {
  14. int num = Integer.parseInt(scanner.nextLine());
  15. rightSum += num;
  16. }
  17. int diff = Math.abs(rightSum-leftSum);
  18.  
  19. if (rightSum == leftSum ){
  20. System.out.printf("Yes, sum =%d%n",leftSum);
  21. }else{
  22. System.out.printf("No, diff =%d%n ",diff);
  23. }
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement