Advertisement
Spocoman

03. Fold and Sum

Oct 22nd, 2024
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Arrays;
  3.  
  4. class Main {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         int[] arr = Arrays
  9.                 .stream(scanner.nextLine().split(" "))
  10.                 .mapToInt(Integer::parseInt)
  11.                 .toArray();
  12.  
  13.         int[] sumArr = new int[arr.length / 2];
  14.  
  15.         for (int j = 0; j < arr.length / 4; j++) {
  16.             sumArr[j] = arr[arr.length / 4 - (1 + j)] + arr[arr.length / 4 + j];
  17.             sumArr[sumArr.length / 2 + j] = arr[arr.length / 2 + j] + arr[arr.length - (1 + j)];
  18.         }
  19.  
  20.         for (int element : sumArr) {
  21.             System.out.printf("%d ", element);
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement