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, rightSum = 0;
- for (int i = 0; i < n; i++) {
- leftSum += Integer.parseInt(scanner.nextLine());
- }
- for (int i = 0; i < n; i++) {
- rightSum += Integer.parseInt(scanner.nextLine());
- }
- if (leftSum == rightSum) {
- System.out.printf("Yes, sum = %d\n", leftSum);
- } else {
- System.out.printf("No, diff = %d\n", Math.abs(leftSum - rightSum));
- }
- }
- }
- ИЛИ:
- 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, rightSum = 0;
- for (int i = -n; i < n; i++) {
- if (i < 0) {
- leftSum += Integer.parseInt(scanner.nextLine());
- } else {
- rightSum += Integer.parseInt(scanner.nextLine());
- }
- }
- if (leftSum == rightSum) {
- System.out.printf("Yes, sum = %d\n", leftSum);
- } else {
- System.out.printf("No, diff = %d\n", Math.abs(leftSum - rightSum));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement