Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package forLoops;
- import java.util.Scanner;
- public class P09LeftAndRightSum {
- 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 = 1; i <= n * 2; i++) {
- int currentNum = Integer.parseInt(scanner.nextLine());
- if (i <= n) {
- leftSum = leftSum + currentNum;
- } else {
- rightSum = rightSum + currentNum;
- }
- }
- if (leftSum == rightSum) {
- System.out.printf("Yes, sum = %d%n", leftSum);
- } else {
- int diff = Math.abs(leftSum - rightSum);
- System.out.printf("No, diff = %d%n", diff);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement