RGAlex

O6. Equal Sum

Feb 2nd, 2021
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1. package ArraysExercise;
  2.  
  3. import java.util.Arrays;
  4. import java.util.Scanner;
  5.  
  6. public class O6EqualSum {
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.         int[] numbers = Arrays.stream(scanner.nextLine().split(" "))
  10.                 .mapToInt(Integer::parseInt).toArray();
  11.  
  12.         boolean isFound = false;
  13.         for (int i = 0; i <= numbers.length - 1; i++) {
  14.  
  15.             int sumLeft = 0;
  16.             int sumRight = 0;
  17.             for (int indexLeft = 0; indexLeft <= i - 1; indexLeft++) {
  18.                 sumLeft += numbers[indexLeft];
  19.             }
  20.  
  21.             for (int indexRight = i + 1; indexRight <= numbers.length - 1; indexRight++) {
  22.                 sumRight += numbers[indexRight];
  23.             }
  24.  
  25.             if (sumLeft == sumRight) {
  26.                 System.out.println(i);
  27.                 isFound = true;
  28.             }
  29.         }
  30.         if (!isFound) {
  31.             System.out.println("no");
  32.         }
  33.     }
  34. }
  35.  
  36.  
Advertisement
Add Comment
Please, Sign In to add comment