Created
June 17, 2016 11:45
-
-
Save Yurlov/0f5dfd0a14dceb66802e6e0ce9d50721 to your computer and use it in GitHub Desktop.
Prog.kiev.ua
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
import java.util.Arrays; | |
public class ArraySumCalculator { | |
public static void main(String[] args) { | |
int[] array = new int[5]; | |
fillArray(array); | |
int sum = sumArray(array); | |
System.out.println(Arrays.toString(array)); | |
System.out.println("Sum is: "+sum); | |
} | |
private static void fillArray(int array[]) { | |
for (int i = 0; i < array.length; i++) { | |
array[i] = (int) (Math.random() * 100); | |
} | |
} | |
private static int sumArray(int[] array) { | |
int sum = 0; | |
for (int i =0;i<array.length;i++) { | |
sum += array[i]; | |
} | |
return sum; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment