Computer Science, asked by bvani7232, 1 day ago

write a program to initialize an array of integers create a new array by adding every two consecutive elements from the start.
for example;
if array length is odd
int []inputarray={1 3 3 4 5 };
first element =6;
second element =7;
int[]outputarray={ 4 7 5}

Answers

Answered by samarthkrv
0

Answer:

public class Main

{

public static void main(String[] args) {

 int[] arr1 = {1,3,3,4,5};

 int[] arr2 = new int[10];

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

     {

         arr2[i] = (arr1[arr1.length-1]+1);

         arr2[i+1] = (arr1[arr1.length]+2);

     }

   System.out.println(arr2);

}

}

Explanation:

Similar questions