Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company.ArraysExercise;
- import java.util.Scanner;
- public class EqualSums {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] input = scanner.nextLine().split(" ");
- int[] numbers = new int[input.length];
- for (int i = 0; i < numbers.length; i++) {
- numbers[i] = Integer.parseInt(input[i]);
- }
- int index = -1;
- for (int i = 0; i < numbers.length; i++) {
- int leftSum = 0;
- int rightSum = 0;
- for (int j = i - 1; j >= 0; j--) {
- leftSum += numbers[j];
- }
- for (int j = i + 1; j < numbers.length; j++) {
- rightSum += numbers[j];
- }
- if (leftSum == rightSum) {
- index = i;
- break;
- }
- }
- if (index != -1) {
- System.out.println(index);
- } else {
- System.out.println("no");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement