Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- public class Equal_Sum {
- public static void main(String[] args) throws IOException {
- BufferedReader Buffer_sum = new BufferedReader(new InputStreamReader(System.in));
- String[] set_id = Buffer_sum.readLine().split(" ");
- int[] numbers = new int[Buffer_sum.readLine().length()];
- for (int i = 0; i < set_id.length; i++) {
- numbers[i] = Integer.parseInt(set_id[i]);
- }
- boolean hasEqual = false;
- for (int i = 0; i < numbers.length; i++) {
- int leftSum = 0;
- int rightSum = 0;
- for (int j = i - 1; j >= 0; j--) {
- leftSum += numbers[j];
- }
- for (int j = i + 1; j < numbers.length; j++) {
- rightSum += numbers[j];
- }
- if (leftSum == rightSum) {
- System.out.println(i);
- hasEqual = true;
- break;
- }
- }
- if(!hasEqual){
- System.out.println("no");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment