Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class E06EqualSum {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] input = scanner.nextLine().split(" ");
- int[] arr = new int[input.length];
- int sumRight = 0;
- int sumLeft = 0;
- int index = 0;
- boolean isNotEqual = false;
- for (int i = 0; i < input.length; i++) {
- arr[i] = Integer.parseInt(input[i]);
- }
- for (int i = 0; i < input.length; i++) {
- index = i;
- if (i > 0) {
- sumLeft += arr[i - 1];
- for (int j = i + 1; j < input.length; j++) {
- sumRight += arr[j];
- }
- if (sumLeft == sumRight) {
- System.out.println(index);
- return;
- } else if(sumLeft != sumRight) {
- isNotEqual = true;
- }
- sumRight = 0;
- }
- }
- if (index == 0) {
- System.out.println(index);
- }
- if (isNotEqual){
- System.out.println("no");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment