Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Equal_Sums {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.print("Enter numbers: ");
- String[]input = sc.nextLine().split("\\s+");
- int[]numbers = new int[input.length];
- for (int i = 0; i < numbers.length; i++) {
- numbers[i] = Integer.parseInt(input[i]);
- }
- for (int i = 0; i < numbers.length ; i++) {
- int leftSum = 0;
- for (int j = 0; j < i; j++) {
- leftSum += numbers[j];
- }
- int rightSum = 0;
- for (int j = i + 1; j < numbers.length ; j++) {
- rightSum += numbers[j];
- }
- if (leftSum == rightSum){
- System.out.println(i);
- System.out.println(numbers[i]);
- return;
- }
- }
- System.out.println("no");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement