Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Lekcii;
- import java.util.Scanner;
- public class CondenseArrayToNumber {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- // Read the integers
- String input = scanner.nextLine();
- // Extract integers from the input string
- String[] inputs = input.split("\\s+");
- int[] nums = new int[inputs.length];
- for (int i = 0; i < inputs.length; i++) {
- nums[i] = Integer.parseInt(inputs[i]);
- }
- // Condense the array
- while (nums.length > 1) {
- int[] condensed = new int[nums.length - 1];
- for (int i = 0; i < nums.length - 1; i++) {
- condensed[i] = nums[i] + nums[i + 1];
- }
- nums = condensed;
- }
- // Print the condensed result
- System.out.println(nums[0]);
- scanner.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement