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 scan = new Scanner(System.in);
- int n = Integer.parseInt(scan.nextLine());
- int leftSum = 0;
- int rightSum = 0;
- for (int i = 0; i < n; i++) {
- int leftNum = Integer.parseInt(scan.nextLine());
- leftSum = leftSum + leftNum;
- }
- // System.out.println(leftSum);
- for (int i = 0; i < n; i++) {
- int rightNum = Integer.parseInt(scan.nextLine());
- rightSum = rightSum + rightNum;
- }
- if (leftSum == rightSum) {
- System.out.printf("Yes, sum = %d", leftSum);
- } else {
- System.out.printf("No, diff = %d", Math.abs(leftSum - rightSum));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment