Advertisement
i_graurov

Untitled

Oct 17th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class equalSums {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. String[] strNumbers = scanner.nextLine().split(" ");
  8. int[] numbers = new int[strNumbers.length];
  9. for (int i = 0; i < strNumbers.length; i++) {
  10. numbers[i] = Integer.parseInt(strNumbers[i]);
  11. }
  12. boolean hasEqualSum = false;
  13. for (int i = 0; i < numbers.length; i++) {
  14. int leftSum = 0;
  15. int rigthSum = 0;
  16.  
  17. for (int j = i - 1; j >= 0; j--) {
  18. leftSum += numbers[j];
  19. }
  20. for (int j = i + 1; j < numbers.length; j++) {
  21. rigthSum += numbers[j];
  22. }
  23. if (leftSum == rigthSum) {
  24. System.out.println(i);
  25. hasEqualSum = true;
  26. break;
  27. }
  28. }
  29. if (!hasEqualSum) {
  30. System.out.println("no");
  31. }
  32.  
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement