write a Program to calculate the sum of difference of adjacent numbers in an array.
Or
Write a program to calculate and return the sum of distances between theadjacent numbers in an array of positive integers.
Answers
Answered by
12
Answer:
Here is your answer:
Code is in java lang:::---
public int findTotalDistance( int input1,int[] input2)
{
int sum=0,difference=0;
for ( int i=0;i<input1-1;i++)
{
difference= Math.abs(input2[i]-input2[i+1]);
sum=sum+ difference;
}
return sum;
}
:))
Similar questions