Advertisement
shniaga

Untitled

Feb 7th, 2019
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. package ArraysExercise;
  2.  
  3. import java.util.Arrays;
  4. import java.util.Scanner;
  5.  
  6. public class EqualSums {
  7. public static void main(String[] args) {
  8. Scanner scanner = new Scanner(System.in);
  9.  
  10.  
  11. int[] numbers = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
  12. int leftSum = 1;
  13. int rightSum = 0;
  14. boolean isEqual = false;
  15.  
  16.  
  17. for (int i = 0; i < numbers.length; i++) {
  18. if (numbers.length == 1) {
  19. System.out.println(0);
  20. isEqual = true;
  21. break;
  22. }
  23. if (leftSum == rightSum) {
  24. System.out.println(i-1);
  25. isEqual = true;
  26. }
  27. leftSum = 0;
  28. rightSum = 0;
  29. for (int j = 0; j < numbers.length; j++) {
  30. if (i > j) {
  31. leftSum += numbers[j];
  32. } else if (i < j) {
  33. rightSum += numbers[j];
  34. }
  35. }
  36.  
  37. }
  38. if (!isEqual) {
  39. System.out.println("no");
  40. }
  41.  
  42. }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement