Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int[] sumNeighbours(int[] intArray){
- int[] resultArray = new int[intArray.length];
- if(intArray.length == 1){
- resultArray[0] = intArray[0];
- return resultArray;
- }
- else{
- for(int index = 0; index < intArray.length; index++){
- if(index == 0){
- resultArray[0] = intArray[0] + intArray[1];
- }
- else if(index == intArray.length - 1){
- resultArray[intArray.length - 1] = intArray[intArray.length - 1] + intArray[intArray.length - 2];
- }
- else{
- resultArray[index] = intArray[index - 1] + intArray[index] + intArray[index + 1];
- }
- }
- return resultArray;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement