Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyClass {
- public static void main(String args[]) {
- java.util.Scanner scanner = new java.util.Scanner(System.in);
- String[] numberStrs = scanner.nextLine().split(" ");
- int[] numbers = new int[numberStrs.length];
- boolean yn = false;
- for(int i = 0;i < numberStrs.length;i++)
- {
- numbers[i] = Integer.parseInt(numberStrs[i]);
- }
- for (int i = 0; i < numbers.length;i++) {
- yn = checkLeftRightSum(i,numbers);
- if (yn) {
- System.out.println(i);
- break;
- }
- }
- if (!yn) {
- System.out.println("no");
- }
- }
- public static boolean checkLeftRightSum(int index, int[] numbers) {
- int leftSum = 0;
- int rightSum = 0;
- if (index == 0) {
- leftSum = 0;
- }
- if (index == numbers.length -1) {
- rightSum = 0;
- }
- for (int i = index;i >= 0; i--) {
- leftSum += numbers[i];
- }
- for (int i = index; i < numbers.length;i++) {
- rightSum += numbers[i];
- }
- return leftSum == rightSum;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement