Created
December 8, 2014 00:04
-
-
Save OlgaKulikova/0b230bd38f40f33912c8 to your computer and use it in GitHub Desktop.
module1.lesson4.task2
This file contains hidden or 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
package module1.lesson4.task2; | |
/* | |
Написать функцию, которая принимает массив чисел в качестве аргумента, увеличивает его первые 3 элемента на 1 | |
и возвращает их сумму как результат. После изменения массив и сумму надо вывести на экран. | |
*/ | |
import java.util.Arrays; | |
public class Main { | |
public static void main(String[] args) { | |
int[] array = new int[] {1, 2, 3, 4, 5}; | |
int sum = changeArray(array); | |
System.out.println(Arrays.toString(array)); | |
System.out.println(sum); | |
} | |
public static int changeArray(int[] array) { | |
int sum = 0; | |
for (int i = 0; i < 3; i++) { | |
array[i]++; | |
sum += array[i]; | |
} | |
return sum; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment