Advertisement
mirozspace

C.A.T

Feb 7th, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3.  
  4. public class Pr7CondenseArrayToNumber {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.         int result = 0;
  8.         int[] num = Arrays
  9.                 .stream(scanner.nextLine().split(" "))
  10.                 .mapToInt(e -> Integer.parseInt(e))
  11.                 .toArray();
  12.         int count = num.length;
  13.         if (num.length == 1) {
  14.             System.out.println(num[0]);
  15.         } else {
  16.             while (count > 1) {
  17.                 for (int i = 0; i < num.length - 1; i++) {
  18.                     num[i] = num[i] + num[i + 1];
  19.                     //System.out.print(num[i] + " ");
  20.                     result = num[i];
  21.                 }
  22.                 num = Arrays.copyOf(num, num.length - 1);
  23.                 count--;
  24.                 //if (count > 1) System.out.print("-> ");
  25.             }
  26.             System.out.println(result);
  27.         }
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement