OpKaTa

Untitled

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