Computer Science, asked by Liyutsararename, 7 months ago

pl solve the following program in java:

Attachments:

Answers

Answered by Oreki
1

import java.util.Scanner;

public class Patterns {

static void printAdjacentSum(int[ ] array) {

int length = array.length - 1;

if (length = = 0) return;

int[ ] newArray = new int[length];

for (int i = 0; i < length; i++) {

newArray[i] = array[i] + array[i + 1];

System.out.print(newArray[i] + " ");

}

System.out.println( );

printAdjacentSum(newArray);

}

public static void main(String[ ] args) {

System.out.print("Enter n - ");

Scanner sc = new Scanner(System.in);

int n = sc.nextInt( );

System.out.println("Enter numbers - ");

int[ ] array = new int[n];

for (int i = 0; i < n; i++)

array[i] = sc.nextInt( );

printAdjacentSum(array);

}

}

Similar questions