Skip to content

Commit

Permalink
Sum of Pairs: Edited the Java solution by Etienne Labuschagne
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Pauley committed May 27, 2010
1 parent 1722570 commit ee8a140
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions Snippets/SumPairs/SumOfNeighbours.java
@@ -1,17 +1,18 @@
// Solution by Etienne Labuschagne
// Edited by me to fit in with the other examples

public class SumOfNeighbours
{
public static void main(String[] args)
{
int[] originalArray = new int[]{1,2,3,4,5};
int[] newArray = new int[4];
public class SumOfNeighbours {
public static int[] sumPairs(int[] a) {
int[] newArray = new int[a.length-1];

for (int i = 1; i < originalArray.length; i++)
newArray[i-1] = originalArray[i-1]+originalArray[i];
for (int i = 1; i < a.length; i++)
newArray[i-1] = a[i-1]+a[i];

return newArray;
}

for (int i : newArray)
System.out.println(i);
}
public static void main(String[] args) {
int[] a = new int[]{1,2,3,4,5};
sumPairs(a);
}
}

0 comments on commit ee8a140

Please sign in to comment.