Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class LeftAndRightSum {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- int leftSum = 0;
- int rightSum = 0;
- for (int i = 0; i < n; i++) {
- int num = Integer.parseInt(scanner.nextLine());
- leftSum += num;
- }
- for (int i = 0; i < n; i++) {
- int num = Integer.parseInt(scanner.nextLine());
- rightSum += num;
- }
- int diff = Math.abs(rightSum-leftSum);
- if (rightSum == leftSum ){
- System.out.printf("Yes, sum =%d%n",leftSum);
- }else{
- System.out.printf("No, diff =%d%n ",diff);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement