Advertisement
psi_mmobile

Untitled

Nov 7th, 2022
1,171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 KB | None | 0 0
  1. public class MyClass {
  2.     public static void main(String args[]) {
  3.         java.util.Scanner scanner = new java.util.Scanner(System.in);
  4.         String[] numberStrs = scanner.nextLine().split(" ");
  5.         int[] numbers = new int[numberStrs.length];
  6.         boolean yn = false;
  7.         for(int i = 0;i < numberStrs.length;i++)
  8.         {
  9.             numbers[i] = Integer.parseInt(numberStrs[i]);
  10.         }
  11.         for (int i = 0; i < numbers.length;i++) {
  12.             yn = checkLeftRightSum(i,numbers);
  13.             if (yn) {
  14.                 System.out.println(i);
  15.                 break;
  16.             }
  17.         }
  18.         if (!yn) {
  19.             System.out.println("no");
  20.         }
  21.     }
  22.     public static boolean checkLeftRightSum(int index, int[] numbers) {
  23.         int leftSum = 0;
  24.         int rightSum = 0;
  25.         if (index == 0) {
  26.             leftSum = 0;
  27.         }
  28.         if (index == numbers.length -1) {
  29.             rightSum = 0;
  30.         }
  31.         for (int i = index;i >= 0; i--) {
  32.             leftSum += numbers[i];
  33.         }
  34.         for (int i = index; i < numbers.length;i++) {
  35.             rightSum += numbers[i];
  36.         }
  37.         return leftSum == rightSum;
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement