Advertisement
emodev

Untitled

Feb 15th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. package p03_Arrays.Lab;
  2.  
  3. import java.util.Arrays;
  4. import java.util.Scanner;
  5.  
  6. public class P07_CondenseArrayToNumber {
  7.     public static void main(String[] args) {
  8.         Scanner console = new Scanner(System.in);
  9.         int[] nums = Arrays.stream(console.nextLine().split(" "))
  10.                 .mapToInt(Integer::parseInt).toArray();
  11.  
  12.         int[] condensed = new int[nums.length - 1];
  13.  
  14.         for (int i = 0; i < condensed.length; i++) {
  15.             nums = condensed(nums);
  16.         }
  17.  
  18.         System.out.println(nums[0]);
  19.  
  20.     }
  21.  
  22.  
  23.     private static int[] condensed(int[] nums) {
  24.         int[] condensed = new int[nums.length - 1];
  25.         for (int i = 0; i < condensed.length; i++) {
  26.             condensed[i] = nums[i] + nums[i + 1];
  27.         }
  28.         return condensed;
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement