Advertisement
Again_89

Za Elena

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