-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sum of Pairs: Edited the Java solution by Etienne Labuschagne
- Loading branch information
Andreas Pauley
committed
May 27, 2010
1 parent
1722570
commit ee8a140
Showing
1 changed file
with
12 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |