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