Advertisement
Krassi_Daskalova

EqualLeftSumRightSum

Jun 16th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 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. String[] input = scanner.nextLine().split(" ");
  7. int[] numbers = new int[input.length];
  8.  
  9. for (int i = 0; i < numbers.length; i++) {
  10. numbers[i] = Integer.parseInt(input[i]);
  11. }
  12. for (int i = 0; i < numbers.length; i++) {
  13. int leftSum = 0;
  14. for (int j = 0; j < i; j++) {
  15. leftSum += numbers[j];
  16. }
  17. int rightSum = 0;
  18. for (int j = i + 1; j < numbers.length; j++) {
  19. rightSum += numbers[j];
  20. }
  21. if (leftSum == rightSum) {
  22. System.out.println(i);
  23. return;
  24. }
  25. }
  26. System.out.println("no");
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement