Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Sum of Pairs: Edited the Java solution by Etienne Labuschagne

  • Loading branch information...
commit ee8a140ae8c90aec8f49059e034f728ab2a1ef1f 1 parent 1722570
@apauley authored
Showing with 12 additions and 11 deletions.
  1. +12 −11 Snippets/SumPairs/SumOfNeighbours.java
View
23 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);
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.