Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main
- {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.print("Enter n= ");
- int n = Integer.parseInt(sc.nextLine());
- int[] array = new int[n];
- for(int i =0;i < array.length;i++){
- System.out.print("Element[" + i + "] = " );
- array[i] = Integer.parseInt(sc.nextLine());
- }
- //Condensing an array of integers by summing adjacent couples of elements until a single number is obtained
- int[] condensed = new int[n-1];
- while(n > 1){
- condensed = new int[n-1];
- for(int i = 0;i<condensed.length;i++){
- condensed[i] = array[i] + array[i+1];
- array[i] = condensed[i];
- }
- n--;
- }
- System.out.println(condensed[0]);
- }
- }
Add Comment
Please, Sign In to add comment