deyanmalinov

06. Equal Sums

Feb 15th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.00 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.*;
  4.  
  5. public class Main {
  6.         public static void main(String[] args) {
  7.             Scanner scan = new Scanner(System.in);
  8.             String [] line = scan.nextLine().split(" ");
  9.             int [] nums = new int[line.length];
  10.             for (int i = 0; i < nums.length; i++) {
  11.                 nums[i] = Integer.parseInt(line[i]);
  12.             }
  13.             boolean ind = false;
  14.             for (int i = 0; i < nums.length; i++) {
  15.                 int lsum = 0, rsum =0;
  16.                 for (int j = i-1; j >=0 ; j--) {
  17.                     lsum += nums[j];
  18.                 }
  19.                 for (int j = i+1; j < nums.length; j++) {
  20.                     rsum += nums[j];
  21.                 }
  22.                 if (lsum==rsum){
  23.                     System.out.print(i);
  24.                     ind=true;
  25.                     break;
  26.                 }
  27.             }
  28.             if (ind != true){
  29.                 System.out.println("no");
  30.             }
  31.         }
  32.  
  33. }
Add Comment
Please, Sign In to add comment